An example of an invalid order and limit Firestore query

An example of an invalid order and limit Firestore query

Documentation pages that include this code sample

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

Code sample

Go

// Note: This is an invalid query. It violates the constraint that range
// and order by are required to be on the same field.
query := cities.Where("population", ">", 2500000).OrderBy("country", firestore.Asc)

Java

Query query = cities.whereGreaterThan("population", 2500000L).orderBy("country");

Node.js

citiesRef.where('population', '>', 2500000).orderBy('country');

PHP

$invalidRangeQuery = $citiesRef
    ->where('population', '>', 2500000)
    ->orderBy('country');

Python

cities_ref = db.collection(u'cities')
query = cities_ref.where(u'population', u'>', 2500000).order_by(u'country')
results = query.stream()

Ruby

query = cities_ref.where("population", ">", 2_500_000).order("country")

What's next

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