Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to accomplish WHERE IN query in Cloud Firestore [duplicate]

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?

like image 845
God Himself Avatar asked Dec 06 '22 12:12

God Himself


1 Answers

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.

like image 161
Doug Stevenson Avatar answered Mar 08 '23 06:03

Doug Stevenson