4

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 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

3 Comments

This is great thanks! Just curious to know how I would use get() with multiple queries and return a stream. The limit 10 is a bit concerning lol.
I don't know - I suggest asking a new question.
any solution to requesting them individually? I am currently trying to do exactly that. I have user which contains a list of playlistIds, and trying to load all the users playlists content asynchronously on start

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.