在多个字段上对 Firestore 查询进行排序

在多个字段上对 Firestore 查询进行排序

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

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

PHP

$query = $citiesRef->orderBy('state')->orderBy('population', 'DESC');

Python

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

Ruby

query = cities_ref.order("state").order("population", "desc")

后续步骤

如需搜索并过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器