zee
zee

Reputation: 666

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

Upvotes: 4

Views: 2333

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317322

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

Upvotes: 6

Related Questions