Google Cloud Firestore 仅查询时间戳早于 x 的文档

Leo*_*aus 1 javascript node.js firebase google-cloud-functions google-cloud-firestore

FieldValue.serverTimestamp()我正在寻找正确的语法来获取时间戳字段 ( ) 已存在 x 天的文档的 documentSnapshot 。

例如:在我的集合中,每个文档都有时间戳字段“ createdAt”。createdAt"我有一个每日计划的云功能,可以获取并记录“”超过 5 天的所有文档。

我的目标是哪种语法?

Dou*_*son 6

您可以使用日期对象通过比较来过滤查询:

const date = new Date(Date.now() - x * 24 * 60 * 60 * 1000)  // x days ago
collectionRef.where('createdAt', '<', date)
Run Code Online (Sandbox Code Playgroud)