Ordering and limiting Firestore queries in descending order

Ordering and limiting Firestore queries in descending order

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();

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