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.
CodePudding user response:
If you want to read/query all subCollectionA
collections, you can use a collection group query. So:
FirebaseFirestore.instance.collectionGroup('subCollectionA').get();