Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  137] [ 6]  / answers: 1 / hits: 10981  / 5 Years ago, sat, june 15, 2019, 12:00:00

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


More From » firebase

 Answers
4

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.



index


[#7274] Thursday, June 13, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
manuel

Total Points: 747
Total Questions: 96
Total Answers: 95

Location: Argentina
Member since Thu, Mar 18, 2021
3 Years ago
manuel questions
Sat, Mar 28, 20, 00:00, 4 Years ago
Fri, Jan 17, 20, 00:00, 4 Years ago
Sun, Jun 30, 19, 00:00, 5 Years ago
Sat, Feb 9, 19, 00:00, 5 Years ago
;