[英]Firebase Firestory query where stored timestamp is in the past
I need to delete all Documents which have a timestamp (stored in a field) prior to today. 我需要删除今天之前所有带有时间戳(存储在字段中)的文档。
The timestamp is created in the Firestore GUI. 时间戳是在Firestore GUI中创建的。 The following query doesnt return any docs. 以下查询不返回任何文档。
collectionRef
.where('timestampFieldName', '<', Date.now())
.get()
What exactly is a timestamp, created in the GUI and how to compare it with any date? 在GUI中创建的时间戳究竟是什么,以及如何将其与任何日期进行比较?
Whenever passing a date to Firestore, you should pass in an actual Date
object. 每当将日期传递给Firestore时,都应传递一个实际的Date
对象。 Date.now()
returns a timestamp, which is just a number and not a Date
object itself. Date.now()
返回一个时间戳,它只是一个数字,而不是Date
对象本身。 To get the actual Date
for the same value, use new Date()
. 要获得具有相同值的实际Date
,请使用new Date()
。 So: 所以:
collectionRef
.where('timestampFieldName', '<', new Date())
.get()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.