I have tried to figure out how to return a query based on whether the values are in an array I have client side. I so far have found nothing regarding the issue. Is this possible?
Asked
Active
Viewed 1.5k times
4
-
See https://stackoverflow.com/a/46773341/209103 – Frank van Puffelen Dec 29 '17 at 23:37
-
Firestore now supports "IN" queries: https://firebase.googleblog.com/2019/11/cloud-firestore-now-supports-in-queries.html – kidroca Nov 14 '19 at 09:13
1 Answers
16
Firestore now supports "IN" queries: Announcement Documentation
Example:
let citiesRef = db.collection("cities")
citiesRef.whereField("country", in: ["USA", "Japan"])
Before November 2019
In Firestore, there is no "where in" like you might be used to with SQL.
If you know the values you want to query, perform different queries for each one, and call getDocument() on each of the DocumentReference objects. You typically would do this in a loop an collect the results yourself.

Luca Invernizzi
- 6,489
- 3
- 28
- 26

Doug Stevenson
- 297,357
- 32
- 422
- 441
-
Yes, but this can become very slow and take up a lot of data when you have thousands of values you need to check. I currently need to check if every user returned from another api is online. The online value is stored with each user ID. I need to check if connection == online && userId is in (array returned from api). I cannot do this thousands of times, or users data would be used up and it would be very slow. – God Himself Dec 29 '17 at 21:29
-
You might want to ask a new question specifically about what you're trying to do, starting with the details you just shared and the code you've written so far. It might be the case that you need a better data model than some unsupported query. – Doug Stevenson Dec 29 '17 at 21:43
-
1Firestore now supports "IN" queries: https://firebase.googleblog.com/2019/11/cloud-firestore-now-supports-in-queries.html – kidroca Nov 14 '19 at 09:13