Ordering and limiting Firestore queries

Ordering and limiting Firestore queries

Documentation pages that include this code sample

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

Code sample

Go

query := cities.OrderBy("name", firestore.Asc).Limit(3)
query := cities.OrderBy("name", firestore.Asc).LimitToLast(3)

Java

Query query = cities.orderBy("name").limit(3);
Query query = cities.orderBy("name").limitToLast(3);

Node.js

const firstThreeRes = await citiesRef.orderBy('name').limit(3).get();

PHP

$query = $citiesRef->orderBy('name')->limit(3);

Python

cities_ref = db.collection("cities")
query = cities_ref.order_by("name").limit_to_last(2)
results = query.get()

Ruby

query = cities_ref.order("name").limit(3)

What's next

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