使用 ISOString 但只获取日期的 firebase

firebase where using ISOString but only take date

所以我正在编写 firebase 命令,如果 firebase 字段中的日期与我确定的变量相等,则获取一些文档。

我的 firebase 中所有与日期相关的字段总是被转换 toISOString,

const today = moment().toISOString();

admin.firestore()
     .collection("orders").where("dueDate", "==", today)
     .get()

但后来我注意到,如果我在我的 where 函数上做 isEqual 只想从特定日期获取文档,那么我不会得到它,因为 toISOString 包含小时、分钟、秒。像这样

2020-08-02T19:14:22.104562

如果我想在

获取所有文件怎么办
2020-08-02

我该怎么做?

使用您现在拥有的数据:

admin.firestore()
    .collection("orders")
    .where("dueDate", ">=", "2020-08-02")
    .where("dueDate", "<", "2020-08-03")
    .get()

另一种方法(可能是更好的方法)是存储日期的 YYYY-MM-DD 字符串(您可以将其格式化为 moment 以及在 home page 上显示的格式) ,并简单地查询是否相等:

admin.firestore()
    .collection("orders")
    .where("dueDate", "==", "2020-08-02")
    .get()