【问题标题】:Google Cloud Firestore only query documents where timestamp is older than xGoogle Cloud Firestore 仅查询时间戳早于 x 的文档
【发布时间】:2019-09-04 21:03:09
【问题描述】:

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

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

我的目标是哪种语法?

【问题讨论】:

    标签: javascript node.js firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-12-26
      • 2020-10-22
      • 2020-06-14
      • 2018-12-20
      • 1970-01-01
      • 1970-01-01
      • 2021-05-11
      • 2019-09-03
      • 1970-01-01
      相关资源
      最近更新 更多