Firestore OrderBy和何处发生冲突 [英] Firestore OrderBy and Where conflict
问题描述
我可以从Firestore数据库中简单地获取数据,但是我想使用一些排序和条件条件对数据进行分页.因此,我尝试使用一些基本的过滤器获取数据,但是在docs
I have simple fetch data from my Firestore db, but i would like to paginate it with some orderring and where conditions. So i am trying to fetch data with some basic filters, but face error, in docs https://firebase.google.com/docs/firestore/query-data/order-limit-data described that only for range <, <=, >, >= should use orderBy and where for same field, but i need only full match (==)
node v8.12.0, express, firebase functions
model.collection
.orderBy("dateCreated", 'desc')//timeStamp
.where('tenantId', '==', 'f8XnOVUKob5jZ29oM9u9')
.limit(10)
.get()
.then((snapshot) => {
res.send(snapshot);
}).catch((error) => res.send(error));
got next error
{
"code": "failed-precondition",
"name": "FirebaseError"
}
i have results only when use where or orderBy separetly but not in same time
When working with compound queries, you need to create an index for your queries. Your query fails because you didn't create indexes for
dateCreated
tenantId
Your index tab should have something similar to the following, with your indexed fields.
这篇关于Firestore OrderBy和何处发生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!