Flutter Firebase get documents by array of IDs

Viewed 1423

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);
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().

Related