I tried to access the subcollection 'match' using docs map.
final firestore = FirebaseFirestore.instance.collection('time').get();
firestore.docs.map((e) {
DateTime dt = e.data()['time'];
e.collection('match'); // How to access its subcollection
})
How can I access the subcollection 'match' on each document and at the same time accessing the 'time' field.
CodePudding user response:
Your firestore
variable is a Future<QuerySnapshot>
object, and you're missing an await
or then
to wait for the future to resolve:
final firestore = FirebaseFirestore.instance.collection('time').get();
final snapshot = await firestore;
You can then access a subcollection of each time
document with:
snapshot.docs.map((doc) {
...
var matchCollection = doc.reference.collection('match');
})
You might also want to look at using a collection group query to read/query all match
collections in one go.