我从 Firestore 数据库中简单地获取数据,但我想使用一些 orderring 和 where 条件对其进行分页。所以我尝试使用一些基本过滤器获取数据,但在文档 https://firebase.google.com/docs/firestore/query-data/order-limit-data 中遇到错误描述仅对于范围 <、<=、>、>= 应该对同一字段使用 orderBy 和 where,但我只需要完全匹配 (==)
节点 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));
出现下一个错误
{
"code": "failed-precondition",
"name": "FirebaseError"
}
仅当单独使用 where 或 orderBy 但不同时使用时才会有结果
最佳答案
使用 compound queries 时,您需要创建一个 index for your queries 。您的查询失败,因为您没有为
创建索引dateCreated
tenantId
您的索引选项卡应具有类似于以下内容的内容,以及您的索引字段。
关于javascript - Firestore OrderBy 和Where 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56614131/