Ordering a Firestore query on multiple fields

Ordering a Firestore query on multiple fields

Code sample

Go

query := client.Collection("cities").OrderBy("state", firestore.Asc).OrderBy("population", firestore.Desc)

Java

Query query = cities.orderBy("state").orderBy("population", Direction.DESCENDING);

Node.js

const byStateByPopRes = await citiesRef.orderBy('state').orderBy('population', 'desc').get();

Python

cities_ref = db.collection(u'cities')
cities_ref.order_by(u'state').order_by(
    u'population', direction=firestore.Query.DESCENDING)