Ordering and limiting Firestore queries in descending order

Stay organized with collections Save and categorize content based on your preferences.

Ordering and limiting Firestore queries in descending order

Explore further

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

Code sample

C#

Query query = citiesRef.OrderByDescending("Name").Limit(3);

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.