Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firebase get documents by array of IDs

How would I get a Query of documents from a collection using a list of IDs? Let's says I have the following:

List<String> someList = ['abc123', 'def456', 'hij789']; // Need to query for these documentIDs

I would normally do the following. But this obviously won't work since I need to query the documentIDs.

Query query = Firestore.instance
        .collection(APIPath.products())
        .where('someField', whereIn: someList);
like image 578
zee Avatar asked Aug 31 '25 01:08

zee


1 Answers

Try using FieldPath.documentId().

Query query = Firestore.instance
        .collection(APIPath.products())
        .where(FieldPath.documentId(), whereIn: someList);

Note that you are limited to 10 items in the list, and this might actually be slower than just requesting each document individually with get().

like image 141
Doug Stevenson Avatar answered Sep 02 '25 18:09

Doug Stevenson