Query a Firestore collection with an array_contains_any filter

Query a Firestore collection with an array_contains_any filter

Code sample

Go

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

Java

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

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

Node.js

const coastalCities = await citiesRef.where('regions', 'array-contains-any',
    ['west_coast', 'east_coast']).get();

Python

cities_ref = db.collection(u'cities')

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

Ruby

cities_ref = firestore.col collection_path
costal_cities = cities_ref.where "regions", "array-contains-any", ["west_coast", "east_coast"]

What's next

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