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
There is no way to get documents from different collections or sub-collections in a single query. Firestore doesn't support queries across different collections in one go unless we are using a collection group query.
By default, a query retrieves all documents that satisfy the query in ascending order by document ID. You can specify the sort order for your data using orderBy() , and you can limit the number of documents retrieved using limit() . Note: An orderBy() clause also filters for existence of the given field.
Save this answer. Show activity on this post. Yes, queries are still case sensitive.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With