Ordering and limiting Firestore queries in descending order

Ordering and limiting Firestore queries in descending order

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.Desc).Limit(3)

Java

Query query = cities.orderBy("name", Direction.DESCENDING).limit(3);

Node.js

const lastThreeRes = await citiesRef.orderBy('name', 'desc').limit(3).get();

PHP

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

Python

cities_ref = db.collection(u'cities')
query = cities_ref.order_by(
    u'name', direction=firestore.Query.DESCENDING).limit(3)
results = query.stream()

Ruby

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

What's next

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