【问题标题】:Firestore reads specific collection dataFirestore 读取特定的集合数据
【发布时间】:2023-02-07 22:10:52
【问题描述】:

这是我的firestore,我想读取“RechargeCoin”集合中的所有数据,我试了很多方法都不能,谁能帮帮我 --> 用户/uid/RechargeCoin/postid

我想获取“UID”和“PostID”的所有内容,怎么办? 这是我的代码

 let db = Firestore.firestore()
        db.collection("Users").document().collection("RechargeCoin")
            .order(by: "date", descending: true)
        
            .addSnapshotListener { (snapshot, error) in

【问题讨论】:

    标签: ios google-cloud-firestore


    【解决方案1】:

    从您的查询来看,您并不特别关注users 集合中的任何文档,只需要RechargeCoin 子集合中的文档听起来像是使用db.collectionGroup("RechargeCoin")Collection group queries 的完美工作,如下所示:

    let db = Firestore.firestore()
      .db.collectionGroup("RechargeCoin")
      .order(by: "date", descending: true)
      .getDocuments { (snapshot, error) in
        if let err = err {
          print("Error getting documents: (err)")
        } else {
          for document in querySnapshot!.documents {
            print("(document.documentID) => (document.data())")
          }
        }
      }
    

    参考自此thread

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2021-06-30
      • 2019-05-06
      相关资源
      最近更新 更多