Query a Firestore collection with an in filter

Query a Firestore collection with an in filter

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample

Go

cities := client.Collection("cities")
query := cities.Where("country", "in", []string{"USA", "Japan"}).Documents(ctx)

Java

CollectionReference citiesRef = db.collection("cities");

Query query = citiesRef.whereIn("country", Arrays.asList("USA", "Japan"));

Node.js

const usaOrJapan = await citiesRef.where('country', 'in', ['USA', 'Japan']).get();

PHP

$rangeQuery = $citiesRef->where('country', 'in', ['USA', 'Japan']);

Python

cities_ref = db.collection(u'cities')

query = cities_ref.where(u'country', u'in', [u'USA', u'Japan'])
return query

Ruby

cities_ref = firestore.col collection_path
usr_or_japan = cities_ref.where "country", "in", ["USA", "Japan"]

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser