An example of an invalid order and limit Firestore query

Stay organized with collections Save and categorize content based on your preferences.

An example of an invalid order and limit Firestore query

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C#

Query query = citiesRef
    .WhereGreaterThan("Population", 2500000)
    .OrderBy("Country");

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.