Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore - how to do a "reverse" array-contains?

I have a collection users in firestore where one of the fields is "contact_person".

Then I have an array arrNames {'Jim', 'Danny', 'Rachel'} in my frontend and I want to get all users that have either of these names in their "contact_person" field. Something like where("contact_person" IN arrNames)

How could I do that?

like image 895
Jaime Avatar asked May 14 '26 17:05

Jaime


2 Answers

This is currently not possible within the Firestore API. You will need to do a separate get for each document, unless the names happen to be in a single contiguous range.

Also see:

  • FireStore Where In Query
  • Google Firestore - how to get document by multiple ids in one round trip?
like image 52
Frank van Puffelen Avatar answered May 17 '26 12:05

Frank van Puffelen


It is now possible (from 11/2019) https://firebase.googleblog.com/2019/11/cloud-firestore-now-supports-in-queries.html but keep in mind that the array size can't be greater than 10.

db.collection("projects").where("status", "in", ["public", "unlisted", "secret"]);

like image 32
Simon Avatar answered May 17 '26 12:05

Simon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!