最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firestore query date range with using 'where' - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 4

I had to do two things to get this working:

  1. Create a posite index by clicking on the link that showed up in my JavaScript console.

  2. 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

发布评论

评论列表(0)

  1. 暂无评论