Use two ranges for a Firestore query

Use two ranges for a Firestore query

Documentation pages that include this code sample

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

Code sample

Go

stateQuery := cities.Where("state", ">=", "CA").Where("state", "<", "IN")
populationQuery := cities.Where("state", "==", "CA").Where("population", ">", 1000000)

Java

Query validQuery1 =
    cities.whereGreaterThanOrEqualTo("state", "CA").whereLessThanOrEqualTo("state", "IN");
Query validQuery2 = cities.whereEqualTo("state", "CA").whereGreaterThan("population", 1000000);

Node.js

citiesRef.where('state', '>=', 'CA').where('state', '<=', 'IN');
citiesRef.where('state', '==', 'CA').where('population', '>', 1000000);

PHP

$rangeQuery = $citiesRef
    ->where('state', '>=', 'CA')
    ->where('state', '<=', 'IN');

Python

cities_ref = db.collection(u'cities')
cities_ref.where(u'state', u'>=', u'CA').where(u'state', u'<=', u'IN')

Ruby

range_query = cities_ref.where("state", ">=", "CA").where("state", "<=", "IN")

What's next

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