Sim*_*sku 5 javascript firebase google-cloud-firestore
我从我的 Firestore 数据库中获取了简单的数据,但我想用一些排序和 where 条件对其进行分页。所以我试图用一些基本的过滤器来获取数据,但面临错误,在文档https://firebase.google.com/docs/firestore/query-data/order-limit-data 中描述的仅适用于范围 <, <= , >, >= 应该使用 orderBy 和 where 用于相同的字段,但我只需要完全匹配 (==)
node v8.12.0,express,firebase 函数
model.collection
.orderBy("dateCreated", 'desc')//timeStamp
.where('tenantId', '==', 'f8XnOVUKob5jZ29oM9u9')
.limit(10)
.get()
.then((snapshot) => {
res.send(snapshot);
}).catch((error) => res.send(error));
Run Code Online (Sandbox Code Playgroud)
遇到下一个错误
{
"code": "failed-precondition",
"name": "FirebaseError"
}
Run Code Online (Sandbox Code Playgroud)
我只有在单独使用 where 或 orderBy 时才有结果,但不是同时使用
Jun*_* L. 14
使用复合查询时,您需要为查询创建索引。您的查询失败,因为您没有为其创建索引
dateCreated
tenantId
Run Code Online (Sandbox Code Playgroud)
您的索引选项卡应具有类似于以下内容的内容,以及您的索引字段。
| 归档时间: |
|
| 查看次数: |
5504 次 |
| 最近记录: |