【发布时间】:2020-04-17 08:49:38
【问题描述】:
我想查找现在和即将到来(未来 30 天)但也不是过去的事件。
当我将它作为云函数运行时,我得到“不能在多个属性上使用不等式过滤器”。我是如何获得这种类型的数据的。
(忽略日期的东西有点乱,我还在玩)。
// Create date 30 days in future
const searchData: Date = new Date();
searchData.setDate(searchData.getDate() + 30);
// Load data and handle empty respoonse
const response: admin.firestore.QuerySnapshot = await admin
.firestore()
.collection(Collections.EVENTS)
.where("startDate", "<=", admin.firestore.Timestamp.fromMillis(searchData.valueOf()))
.where("endDate", ">=", admin.firestore.Timestamp.fromMillis(new Date().valueOf()))
.where("public", "==", true)
.limit(NUMBER_OF_EVENTS)
.get();
编辑: 我想知道数据结构/查询方法,它将允许我返回事件集合中现在正在进行或将在下个月开始的所有事件。此外,我希望查询排除已经完成的事件。每个文档(事件)上都有一个 startDate 和 endDate 时间戳。
【问题讨论】:
-
您不能在单个查询中对多个字段使用范围比较,但如果您编辑问题以说明您的查询应该做什么(英文),可能会有一种解决方法我们可以提供帮助。它可能涉及执行两个查询并合并结果。
-
感谢您的回复,我已经更新了底部的问题,并描述了我正在寻找的行为。
-
谢谢。您的问题对我帮助很大(确实是这个问题。我什至不滚动答案哈哈)。谢谢。
标签: node.js firebase google-cloud-firestore firebase-admin