I have an ArrayList which contains all the ids I want to fetch. Is there a way I can fetch multiple documents and their field values using the list. Also, if I have to manually create a for loop to get each document, how shall I do it?
Firestore data structure:
Users:
user1:
field1 :
field2 :
field3 :
field4 :
user2:
field1 :
field2 :
field3 :
field4 :
user3:
field1 :
field2 :
field3 :
field4 :
The list contains : user1,user2,user3 and so on...
Edit 1:
I tried to get it using a for loop but it gives a null pointer exception
at FriendsData.add(userDetails);
for (String doc : list_of_Friends) {
FirebaseFirestore.getInstance().collection("Users").document(doc).get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
FamilyMember userDetails = documentSnapshot.toObject(FamilyMember.class);
FriendsData.add(userDetails);
}
});
Edit 2:
Another logic for the loop also gives the same error.
When I log, I can see that both the doc
& ds.getId()
are getting values
FirebaseFirestore.getInstance().collection("Users").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful())
for (DocumentSnapshot ds : task.getResult()){
for (String doc : list_of_Friends) {
if(ds.getId().equals(doc)){
FriendsData.add(ds.toObject(FamilyMember.class));
}
}
}
}
});