【问题标题】:Query on getting product that will expire in next 10 days from firestore查询从firestore获取未来10天到期的产品
【发布时间】:2020-12-07 23:07:20
【问题描述】:

我创建了一个集合,其有效期存储在云 Firestore 中。我想获取所有将在未来 10 天内过期的产品。我想将此通知给用户。请帮忙。

Products(collection)---(docId)---(name)Product1--expireDate(Timestamp)--
                    --(docId)----   (name)Product2---expiryDate(Timestamp).

不确定是否正确

Firebase.firestore().collection("product").where('expiryDate' == new Date()+10)

提前致谢。

【问题讨论】:

  • 请编辑问题以显示您编写的任何未按预期方式工作的代码。如果您显示实际数据而不仅仅是文档层次结构也会很有帮助。

标签: typescript firebase ionic-framework google-cloud-firestore


【解决方案1】:

首先您需要创建合适的日期进行比较:

let date = new Date();
date.setDate(date.getDate() + 10);

你可以创建一个查询:

Firebase.firestore().collection("Products").where("expiryDate","<",date);

where的使用方法是here

【讨论】:

    猜你喜欢
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 2016-08-22
    • 2022-07-10
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    相关资源
    最近更新 更多