Query a Firestore collection with an array_contains filter

Query a Firestore collection with an array_contains filter

Documentation pages that include this code sample

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

Code sample

Go

query := cities.Where("regions", "array-contains", "west_coast").Documents(ctx)

Java

CollectionReference citiesRef = db.collection("cities");
Query westCoastQuery = citiesRef.whereArrayContains("regions", "west_coast");

Node.js

const westCoastCities = citiesRef.where('regions', 'array-contains',
  'west_coast').get();

PHP

$containsQuery = $citiesRef->where('regions', 'array-contains', 'west_coast');

Python

cities_ref = db.collection(u'cities')

query = cities_ref.where(u'regions', u'array_contains', u'west_coast')

Ruby

cities_ref = firestore.col collection_path
cities = cities_ref.where "regions", "array-contains", "west_coast"

What's next

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