Query a Firestore collection with a boolean eq filter

Query a Firestore collection with a boolean eq filter

Code sample

Go

query := client.Collection("cities").Where("capital", "==", true)

Java

// Create a reference to the cities collection
CollectionReference cities = db.collection("cities");
// Create a query against the collection.
Query query = cities.whereEqualTo("capital", true);
// retrieve  query results asynchronously using query.get()
ApiFuture<QuerySnapshot> querySnapshot = query.get();

for (DocumentSnapshot document : querySnapshot.get().getDocuments()) {
  System.out.println(document.getId());
}

Node.js

// Create a reference to the cities collection
const citiesRef = db.collection('cities');

// Create a query against the collection
const allCapitalsRes = await citiesRef.where('capital', '==', true).get();

Python

cities_ref = db.collection(u'cities')

query = cities_ref.where(u'capital', u'==', True)