0
votes

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();
}
1

1 Answers

0
votes

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 
      });
    });
  });
});