简体   繁体   中英

get data from all the docs of firebase in flutter

在此处输入图片说明

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM