0
votes

I have list of Collection IDs. Is there any way I can query and get all the documents under these collection ids? without iterating to each id in the list. enter image description here

Thank you for your time

1
If you're asking how to run a query across multiple collections, the answer is that you can't (yet). See stackoverflow.com/questions/46573014/…Frank van Puffelen
I only see a single collection (user) which contains a few documents represented by their document ids. What do you really want to query? Please responde with @AlexMamoAlex Mamo
@AlexMamo Yes, There is only one collection user. In my code I have list of document ids form this user collection. I want to query this collection in a way so that it gives me all the documents that matches the ids in the list. List list = ['C0smTfprmfdw...', 'test', 'yhwDu2qvTRX...']Sam

1 Answers

1
votes

According to your last comment, I understand that you want to get all documents within a single collection and not to query multiple collections, which is not possbile for the moment in Firestore.

If you have a list of ids, then simply iterate over it and create for each id in the list the corresponding DocumentReference and then add all those references to a List<DocumentReference>. After that, iterate over the new list and for each reference create a Task and then add all those Tasks objects to List<Task<DocumentSnapshot>>.

In the end, just pass the list of Tasks to Tasks's whenAllSuccess() method:

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) {
            YourObject yb = ((DocumentSnapshot) object).toObject(YourObject.class);
            Log.d("TAG", yb.getPropertyName);
        }
    }
});

In code it looks like my answer from this post: