dragonfly02
dragonfly02

Reputation: 3679

firestore query filter based on a collection

I have a book collection in firestore, by design each document has an id (say it's integer ids like 0, 1, 2..); I want to query the collection by filtering a random collection of document id e.g. [2, 5, 23, 54], note that these ids are random so I can't use range filter like isGreaterThan. I want to avoid querying once for each filtered id as it may read the database too many times (which can be costly).

I tried to use Firestore.instance.collection('book')where('id', array_contains:[ filtered id]) but this doesn't work since id isn't a collection field.

Upvotes: 0

Views: 3305

Answers (1)

Jack Woodward
Jack Woodward

Reputation: 1001

Currently you cant do or queries in array_contains its definitely a feature people want and so id recommend logging your feature request with support. However in the meantime because your queries wont intersect it's the same cost to just do individual queries and bring the results together into a main array. Not sure on your language so cant give an example but its just doing 4 queries in your example and having them all update a master array.

Upvotes: 1

Related Questions