在我收藏的 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
内的子集合中的所有文档(每个文档只有一个 String 字段)。我可以执行 doc.getDocument
来获取 doc
本身,我用它来获取字符串字段,但我不知道如何获取文档在其子集合中。
最佳答案
首先获取子集合:
doc.getDocument().getReference().getCollection("subcollection")
然后您像以前一样(或如 this documentation section 中所示)将文件放入其中。
关于android - 文档中文档的 Firebase Firestore 子集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50281966/