【问题标题】:Compare two Firestore Timestamps by "greater than" [duplicate]通过“大于”比较两个 Firestore 时间戳 [重复]
【发布时间】:2019-08-26 18:55:23
【问题描述】:

我正在尝试比较云函数中的两个时间戳。

不是“平等”(如here 所述),而是“大于”。

我不知道问题出在哪里,但我无法让它工作。

这是我的代码,很简单:

 const lastDayUnread = await admin.firestore()
     .collection('/unread')
     .where('last_message', '>', 'last_seen')
     .get()

我也尝试使用 .seconds 属性,但仍然没有:

.where('last_message.seconds', '>', 'last_seen.seconds')

如果我从 JS 客户端执行相同的查询,它会起作用,并且控制台会显示我的文档 last_seen 和 last_message 属性中有一个 Timestamp 对象。

【问题讨论】:

  • 为什么如果您使用时间戳,您会将其用作对象“last_message.seconds”?

标签: firebase timestamp google-cloud-firestore


【解决方案1】:

Cloud Firestore 中 where 子句的右侧必须是文字值。不支持查找其他字段的值。

典型的解决方法是使用last_message.seconds - last_seen.seconds 存储一个附加字段,然后:

.where('delta_seconds', '>', 0)

【讨论】:

猜你喜欢
  • 2019-02-14
  • 2012-02-04
  • 2015-01-02
  • 2021-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多