简体   繁体   中英

Firestore query date range with using 'where'

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('completed', '==', 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('completed', '==', true) 
query = query.where('publishdate', '>', 1555567200000)
query.get().then(...)

but no result

I had to do two things to get this working:

  1. Create a composite 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.com/gufogib/edit?js,console

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM