【问题标题】:Firebase Firestore subcollection of documents from documentFirebase Firestore 文档中的文档子集合
【发布时间】:2018-10-21 06:13:54
【问题描述】:

在我的集合的 SnapshotListener 中,我通过以下方式遍历文档:

for (DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()) {
    if (doc.getType() == DocumentChange.Type.ADDED) {
        String somestr = doc.getDocument.getString("someField");
        // retrieve collection here
    }
}

在 for 循环中的每个文档中,我们称之为 doc,我在 Cloud Firestore 上还有另一个文档集合。我想在doc 的子集合中检索所有文档(每个文档只有一个字符串字段)。我可以使用doc.getDocument 来获取doc 本身,我正在使用它来获取字符串字段,但我不知道如何获取其子集合中的文档。

【问题讨论】:

    标签: android firebase google-cloud-firestore


    【解决方案1】:

    你首先得到子集合:

    doc.getDocument().getReference().getCollection("subcollection")
    

    然后您就可以像以前一样在其中获取文档(或如this documentation section 所示)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-04
      • 2021-01-23
      • 2021-05-09
      • 2020-08-25
      • 2019-11-13
      • 2019-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多