0

I am having an array of document-id(s). And I want to retrieve only the documents who's ID is present in array. I want to show them in Recycle-View.

Example:

["rRfuYlrGgLClZui4LmbN", "dKKEdAXHrRSQ7UzvasWQ", "AL5t6DHbLfAmleaO4WCk"]

If above are my array elements, then how to fetch only these documents?

Top-Master
  • 7,611
  • 5
  • 39
  • 71

1 Answers1

0

You can loop through each document ID and retrieve them as desired, each request returns a Task<Snapshot>.

List<Task<DocumentSnapshot>> tasks = new ArrayList<>();
for (String doc : list_of_Friends) {
    tasks.add(FirebaseFirestore.getInstance().collection("MyCollection").document(doc).get());
}

Tasks.whenAllSuccess(tasks).addOnSuccessListener(new OnSuccessListener<List<Object>>() {
    @Override
    public void onSuccess(List<Object> list) {
        //Do what you need to do with your list
        for (Object object : list) {
           customClass data = ((DocumentSnapshot) object).toObject(customClass.class);
        }
    }
});
DIGI Byte
  • 4,225
  • 1
  • 12
  • 20