1
votes

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
    }
}

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.

1

1 Answers

1
votes

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).