Skip to content
Advertisement

Get the named of Collections from Document on Cloud Firestore

I want to get collections (Col01, Col02, Col03) from the document (Doc01). How can I approach this? Check the attached image. Thanks.

enter image description here

Advertisement

Answer

There is no API for getting a list of collection names that exist within your (Doc01) document. So, unfortunately, you cannot do that on Android. Because you are looking for sub-collections that are nested under a document, the only option that you have is to use DocumentReference’s listCollections() function but is currently available only for Node.js admin clients.

The simplest solution I can think of is to create a collection with a single document, in which you should add an array that contains the names of all sub-collections that exist under your (Doc01) document. To display those names is at simple as displaying the content of a List in Java. This solution will work not only for Android, but for all platforms.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement