使用'where'的Firestore查询日期范围

问题描述 投票:0回答:1

如果今天和状态为真,我需要从集合中获取doc,但似乎没有效果这个查询是否有更好的解决方案?

我的查询:

var query = firebase.firestore().collection("book")
query = query.where('completed', '==', true) 
query = query.orderBy('publishdate').startAt(1555567200000).endAt(1555653599999)
query.get().then(...)

我也尝试过:

var query = firebase.firestore().collection("book")
query = query.where('completed', '==', true) 
query = query.where('publishdate', '>', 1555567200000)
query.get().then(...)

但没有结果

javascript google-cloud-firestore
1个回答
1
投票

我必须做两件事来完成这项工作:

  1. 通过单击我的JavaScript控制台中显示的链接来创建复合索引。 enter image description here
  2. 将时间戳作为正确的Date()而不是数字传递:query = query.orderBy('publishdate').startAt(new Date(1555653600000));

有了它,它对我来说很好。请在此处查看工作示例:https://jsbin.com/gufogib/edit?js,console

© www.soinside.com 2019 - 2024. All rights reserved.