当我的日期字段之一在猫鼬中为空时,如何比较日期字段?

时间:2020-03-13 08:07:57

标签: mongodb mongoose mongodb-query aggregation-framework

当我尝试将日期字段startDate [在mongodb中为null]与另一个字段EndDate [not null]进行比较时,它将引发以下错误。 MongoError: can't convert from BSON type int to Date.

我的模特 StartDate: {type:Date }, EndDate: {type:Date}, 在mongodb中, 日期存储为以下格式的2020-03-13T07:55:10.549+00:00

在控制器中,我使用了聚合函数[mongoose]来比较这些值 { $cond: [{ $eq: [{ $max: "$StartDate" }, "$EndDate"] }, 1, 0] },

当我的日期字段为空时如何处理比较?

0 个答案:

没有答案