I need to grab doc from collection if its today and status true, but it seems not working is there any better solution for this query?
My query:
var query = firebase.firestore().collection("book")
query = query.where('pleted', '==', true)
query = query.orderBy('publishdate').startAt(1555567200000).endAt(1555653599999)
query.get().then(...)
I've also tried:
var query = firebase.firestore().collection("book")
query = query.where('pleted', '==', true)
query = query.where('publishdate', '>', 1555567200000)
query.get().then(...)
but no result
I need to grab doc from collection if its today and status true, but it seems not working is there any better solution for this query?
My query:
var query = firebase.firestore().collection("book")
query = query.where('pleted', '==', true)
query = query.orderBy('publishdate').startAt(1555567200000).endAt(1555653599999)
query.get().then(...)
I've also tried:
var query = firebase.firestore().collection("book")
query = query.where('pleted', '==', true)
query = query.where('publishdate', '>', 1555567200000)
query.get().then(...)
but no result
Share Improve this question edited Apr 20, 2019 at 16:35 test asked Apr 18, 2019 at 23:46 testtest 2,46615 gold badges46 silver badges81 bronze badges 2- Did you create a posite index on that bination of fields? If not, the JavaScript console of your browser should show you a message that explains that this is needed, and a link that takes you directly to the console to create it. – Frank van Puffelen Commented Apr 19, 2019 at 0:29
-
You'll be billed for all documents returned from the server by
query.get()
. – Frank van Puffelen Commented Apr 20, 2019 at 1:04
1 Answer
Reset to default 4I had to do two things to get this working:
Create a posite index by clicking on the link that showed up in my JavaScript console.
Pass in the timestamp as a proper
Date()
instead of a number:query = query.orderBy('publishdate').startAt(new Date(1555653600000));
With that it works fine for me. See a working sample here: https://jsbin./gufogib/edit?js,console