Reputation: 68
My firestore structure looks like this. There is a collection mychats that consists of documents that also consists of different collections. Is there any way i could get the number of collections stored in every document
Upvotes: 0
Views: 119
Reputation: 317352
It's not possible to list or count subcollections using any of the Firestore web or mobile SDKs. You should probably instead keep track of anything you need with your own code that writes to some document that maintains any required counts.
Note that subcollections are not really stored "within" a document. They are merely nested under that document's name. The screenshot you show here actually has missing documents, as you can see from the fact that they are listed in italics in the console.
If you are willing to make a call to a backend, you could use a method like listCollections() to get a list of subcollections nested under a document. The ability to list collections is only available with server SDKs, and not available to web and mobile client SDKs.
I will say that having randomly generated IDs for collection is probably not the best database design. You're probably better off using static names for collections so that you don't have to worry about listing them. If you instead put your randomly named items as documents within a subcollections, you can list them with no problem simply by querying the subcollection.
Upvotes: 2