问题描述
在集合的SnapshotListener中,我正在使用以下命令循环浏览这些文档:
In my collection's SnapshotListener, I have am looping through the documents with:
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
本身,我正在使用它来获取字符串字段,但是我不知道如何获取文档在其子集合中.
And within each document in the for loop, let's call it doc
, I have another collection of documents on Cloud Firestore. I would like to retrieve all documents (each of which just has a single String field) within the subcollection inside doc
. I'm able to do a doc.getDocument
to get doc
itself, which I am using to get a string field, but I don't know how to get the documents in its subcollection.
推荐答案
您首先使用以下方法获得子集合:
You first get the subcollection with:
doc.getDocument().getReference().getCollection("subcollection")
然后,您可以像以前一样将文档保存到其中(或如本文档部分).
And then you get the documents in there like you did before (or as shown in this documentation section).
这篇关于Firebase文档中文档的Firestore子集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!