Query a Firestore collection with an in array filter

Stay organized with collections Save and categorize content based on your preferences.

Query a Firestore collection with an in array filter

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C#

Query query = citiesRef.WhereIn("Regions",
    new[] { new[] { "west_coast" }, new[] { "east_coast" } });

Go

cities := client.Collection("cities")
query := cities.Where("regions", "in", [][]string{{"west_coast"}, {"east_coast"}}).Documents(ctx)

Java

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

Query query =
    citiesRef.whereIn(
        "regions", Arrays.asList(Arrays.asList("west_coast"), Arrays.asList("east_coast")));

Node.js

const exactlyOneCoast = await citiesRef.where('regions', 'in',
    [['west_coast', 'east_coast']]).get();

PHP

$rangeQuery = $citiesRef->where('regions', 'in', [['west_coast'], ['east_coast']]);

Python

cities_ref = db.collection(u'cities')

query = cities_ref.where(
    u'regions', u'in', [[u'west_coast'], [u'east_coast']]
)
return query

Ruby

cities_ref = firestore.col collection_path
exactly_one_cost = cities_ref.where "regions", "in", [["west_coast"], ["east_coast"]]

What's next

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