简体   繁体   中英

Read subcollection from Firestore flutter?

How to read subcollection from flutter firestore. I am using cloud_firestore. I am successfully adding data into firestore but couldn't retrieve it(tried and failed). I want to retrieve subCollection called product Firestore collection

I tried this I don't have the document ID Because it generated automatically from firestore:

 Stream<QuerySnapshot> loadorderdetails(String uid) {
return FirebaseFirestore.instance
    .collection('Users/$userid/Orders')
    .doc()
    .collection("Products")
    .where('uid', isEqualTo: uid)
    .snapshots();
}

You should try this

FirebaseFirestore.instance.collection("Users/$userid/Orders ").get().then((querySnapshot) {
  querySnapshot.docs.forEach((result) {
    FirebaseFirestore.instance
        .collection("Users/$userid/Orders")
        .doc(result.id)
        .get()
        .then((querySnapshot) {
      //print data 
      });
    });
  });
});

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