Skip to content Skip to sidebar Skip to footer

How To Access Sub-collections Across Multiple Documents Within A Single Collection In Firestore?

I have a database structure as follows (simplified for purposes of this question): Collection: registrations -> Document: params = {someParameter: 'value'} -> Documen

Solution 1:

You should definitely use the collectionGroup() method as described there.

Solution 2:

You can use a collection group query to query all documents among collections and subcollections with the same name. So, for the subcollection "orders", you can query all documents in those collections using:

firestore().collectionGroup("orders").get()

If you don't want all of the order documents, you will need to add a filter in the same way that you would any other query. You can only filter using the fields available in each orders document (you can't filter per user unless you have a "user" field in the document to use).

I have read on StackOverflow that FireStore cannot query sub-collections unless the parent document has "regular" fields

This is not true. There is no need to have a parent document in place to query its nested subcollections.

Post a Comment for "How To Access Sub-collections Across Multiple Documents Within A Single Collection In Firestore?"