首页 > 解决方案 > Firestore:如何查询特定时间戳(相等)

问题描述

我希望以下查询起作用

await admin.firestore().collectionGroup(`calenders`).where('appointments', 'array-contains', admin.firestore.Timestamp.fromDate(now)).get()

我有调试数据要测试

const testDate= new Date(2000, 3, 3, 23, 0, 0, 0)
console.log(testDate)
console.log(admin.firestore.Timestamp.fromDate(testDate))

我还以完全相同的方式打印了与 testDate 匹配的文档的时间戳。

Output for test date:
2000-03-03T23:00:00.000Z 
Timestamp { _seconds: 952124400, _nanoseconds: 0 }

Output for real document date
2000-03-03T23:00:00.000Z 
Timestamp { _seconds: 952124400, _nanoseconds: 0 } 

这显然是一样的。现在我检查了。为了比较时间戳,有一个方法叫做isEqual(Timestamp other). 这是否意味着除了将时间戳存储在另一种数据格式中之外,没有其他方法可以使查询工作?

标签: node.jsgoogle-cloud-firestore

解决方案


推荐阅读