Firebase 通过“比较”比较两个Firestore时间戳;大于;

Firebase 通过“比较”比较两个Firestore时间戳;大于;,firebase,timestamp,google-cloud-firestore,Firebase,Timestamp,Google Cloud Firestore,我试图比较云函数中的两个时间戳 不是“平等”(如所述),而是“大于” 我不知道问题出在哪里,但我无法让它工作 这是我的代码,非常简单: const lastDayUnread = await admin.firestore() .collection('/unread') .where('last_message', '>', 'last_seen') .get() 我还尝试使用.seconds属性,但仍然没有: .where('last_message.

我试图比较云函数中的两个时间戳

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

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

这是我的代码,非常简单:

 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对象。

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

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

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

为什么如果你使用的是时间戳,你会将它作为“last_message.seconds”的对象使用?我刚刚发现我之前已经回答了这个问题,所以我以“谢谢”的重复形式结束了这个问题。我不知道那种行为。