Ordering a Firestore query with a filter

Ordering a Firestore query with a filter

Code sample

C#

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

Go

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

query := cities.Where("population", ">", 2500000).OrderBy("population", firestore.Asc)

Java

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

Node.js

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

PHP

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

Python

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

cities_ref = db.collection("cities")
query = cities_ref.where(filter=FieldFilter("population", ">", 2500000)).order_by(
    "population"
)
results = query.stream()

Ruby

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

What's next

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