Firebase Firestore从文档中收集文档

时间:2018-05-10 21:45:56

标签: android firebase google-cloud-firestore

在我的系列的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本身,我用它来获取字符串字段,但我不知道如何在其子集合中获取文档。

1 个答案:

答案 0 :(得分:1)

您首先获得子集合:

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

然后你就像之前那样(或this documentation section所示)在那里得到文件。

相关问题