我已使用以下代码获得queryDocumentSnapshot
:
mFireStore = FirbaseFirestore.getInstance();
mFireStore.collection("myCollection").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
for (DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()) {
if (doc.getType() == DocumentChange.Type.ADDED) {
// Set some data from the doc.getDocument here
mFireStore.collection("myCollection").document(doc.getDocument().getId()).collection("subCollection").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (queryDocumentSnapshots.isEmpty()){
// not found
} else{
List<DocumentSnapshot> hosts = queryDocumentSnapshots.getDocuments();
for (int i = 0; i < hosts.size(); i++){
// Each hosts DocumentSnapshot has a "host" field which contains a reference to a document
// I'd like to follow this reference and get that document
}
}
}
});
我的问题是,一旦我获得了主持人DocumentSnapshots
的列表,我就想关注他们的主持人&#34;包含对文档的引用的字段。我想按照这个参考,在另一端得到文件,但不知道如何。如果您发现我的逻辑存在任何其他问题,请随意指出,因为我对Cloud Firestore不熟悉。