Query a Firestore collection with a cursor start at field filter

Query a Firestore collection with a cursor start at field filter

Explore further

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

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.OrderBy("Population").StartAt(1000000);

Go

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

query := client.Collection("cities").OrderBy("population", firestore.Asc).StartAt(1000000)

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.orderBy("population").startAt(4921000L);

Node.js

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

const startAtRes = await db.collection('cities')
  .orderBy('population')
  .startAt(1000000)
  .get();

PHP

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

$query = $citiesRef
    ->orderBy('population')
    ->startAt([1000000]);

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_start_at = cities_ref.order_by("population").start_at({"population": 1000000})

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.order("population").start_at(1_000_000)

What's next

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