Reputation: 668
i want indivisualscore of all the ids to get printed on the console.
when i search for each indivisual id passed it gives me correct answer. for example
CollectionReference collectionReference = FirebaseFirestore.instance.collection('score');
await collectionReference.doc(widget.uid).collection("indivisualscore").snapshots().listen((event) {
print(event.docs.length);
}
here i am passing widget.uid, gives me indivisualscore of that particular id passed.
but i now want to obtain indivisualscore of all the ids, in the score collection. it has to do something with the length of the doc in score collection,but i am not able to get it correctly.
thanks.
Upvotes: 0
Views: 41
Reputation: 80904
If you want to get the ids inside the collection score
, then you have to do the following:
CollectionReference collectionReference = FirebaseFirestore.instance.collection('score');
var snapshot = await collectionReference.get();
snapshot.docs.forEach((result) {
print(result.id);
});
Reference the collection score
then use get()
to obtain the documents inside that collection, then the property docs
will return a List<DocumentSnapshot>
which you can iterate and get all the ids.
Upvotes: 1