0

enter image description here

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

15 Comments

where did you paste it?
if it is not printing, then its not even entering it.. you have to debug it to check
but for indivisual uid,its printing. i debugged it,and its running your code, but not printing anything.
printing print(snapshot.docs); shows empty erray in the console, and printing just snapshort gives Instance of 'QuerySnapshot' in console
appreciate @PeterHaddad for pointing the error,thankyou so much
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.