对 Firestore 查询进行排序和限制

对 Firestore 查询进行排序和限制

包含此代码示例的文档页面

如需查看上下文中使用的代码示例,请参阅以下文档:

代码示例

Go

query := cities.OrderBy("name", firestore.Asc).Limit(3)
query := cities.OrderBy("name", firestore.Asc).LimitToLast(3)

Java

Query query = cities.orderBy("name").limit(3);
Query query = cities.orderBy("name").limitToLast(3);

Node.js

const firstThreeRes = await citiesRef.orderBy('name').limit(3).get();

PHP

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

Python

cities_ref = db.collection("cities")
query = cities_ref.order_by("name").limit_to_last(2)
results = query.get()

Ruby

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

后续步骤

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