I am trying to run a simple query on Firestore, using both where and orderBy. The query does not work, with no error messages. After some research, I found out that I might need to build index in Firestore. I did that, but once again, this query does not work.
Is there some solutions? Not beeing able to run where + orderBy would be a huge weakness.
Here is the code:
var firestore = firebase.firestore();
firestore.collection(collec_name).where("approved", "==", 1).orderBy('signin_date', 'desc').limit(3).get().then(snapshot => {
snapshot.forEach(doc => {
...
}
})
The query does not work, with no error messages
You're not getting any error messages because you're not actually checking for any errors. Your code should have a catch block to see what went wrong:
var firestore = firebase.firestore();
firestore.collection(collec_name)
.where("approved", "==",1)
.orderBy('signin_date', 'desc')
.limit(3)
.get()
.then(snapshot => {
snapshot.forEach(doc => {
}
})
.catch(error => {
console.error(error)
})
If your query does actually need an index, the error message printed here will give you a link to click that creates the index needed to satisfy this query.
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