【问题标题】:Read subcollection from Firestore flutter?从 Firestore 中读取子集合?
【发布时间】:2021-06-30 08:38:42
【问题描述】:

如何从 Flutter Firestore 中读取子集合。我正在使用 cloud_firestore。我已成功将数据添加到 Firestore,但无法检索它(尝试并失败)。 我想检索名为产品Firestore collection的子集合@

我试过这个我没有文档 ID 因为它是从 firestore 自动生成的:

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

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    你应该试试这个

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

    【讨论】:

      猜你喜欢
      • 2020-02-03
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      • 2019-02-17
      • 2021-03-10
      • 1970-01-01
      相关资源
      最近更新 更多