szervay
szervay

Reputation: 3

How to access collections inside the documents of another collection in flutter

I have a firestore collection A under which I have multiple documents. Every document has 2 collections in it: subCollectionA and subCollectionB. I am currently able to access all the documents inside collection A as follows:

var _a = await FirebaseFirestore.instance.collection('A').get();
for(int i=0; i<_a.docs.length; i++){
    // access _a.docs[i]
}

Is there a way to access the sub-collections inside these documents in flutter?

I tried to find the syntax for this, but I am unable to find it. I tried this, but It's returning a widget and I would like to do these calculations per document in the above code before I display the widgets.

Upvotes: 0

Views: 1160

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598668

If you want to read/query all subCollectionA collections, you can use a collection group query. So:

FirebaseFirestore.instance.collectionGroup('subCollectionA').get();

Upvotes: 1

Related Questions