Reputation: 103
I get this error once I added the Where method, but it works without the Where clause. In collection every document has Boolean called "status".
db.firestore().collection('jobs').where("status","==",true).orderBy("createDate").limit(10).get().then(querySnapshot =>{
})
})
All Help is Appreciated. Thanks!
Upvotes: 5
Views: 10294
Reputation: 6160
Firestore query on more than two fields requires a composite index on that two filed.
So you have to create composite index status
and createDate
.You will get the error like following when you don't have an index.
ERROR Error: The query requires an index. You can create it here: https://console.firebase.google.com/project/admin-e8a7b/database/firestore/indexes?create_index=EgR0ZW1wGgcKA3VpZBACGg0KCXN0YXJ0ZWRBdBADGgwKCF9fbmFtZV9fEAM
at new FirestoreError (vendor.bundle.js:19925)
So when you click this link in error index will be created automatically.
You can also manually create index from firebase console
To combine the equality operator (==) with a range comparison (<, <=, >, or >=), make sure to create a custom index.
Upvotes: 0
Reputation: 598797
Since you're querying on two fields (status
and createDate
), there needs to be a composite index on those two fields. Indices on individual fields are automatically created, but composite indexes are only created when you ask for them.
The error message should contain a link directly to the console to complete that task. If that's not the case, you can create it here.
Upvotes: 9