我想根据减去当前日期小于10天的过期日期对象来过滤集合。

我正在使用下面的代码,但我得到了以毫秒为单位的日期差异。我想要精确的日期差异。
db.metaobject.aggregate(
{ $unwind :'$certifications.expiry_date'},
{$project:{
_id:1,name:1,date-Difference: { $divide:[ {$subtract: [ "$certifications.expiry_date",new Date ]},86400000] }
}
},
{$match:{
dateDifference:{$lte:10}
}
}
)发布于 2018-01-02 22:03:22
如果在node中使用,则不需要计算差值:
直接计算节点js中的日期+ 10,然后直接计算到$lte:
var date = new Date();
var date10 = new Date(date.getTime());
date10.setDate(date10.getDate() + 10);
db.metaobject.aggregate(
{ $unwind :'$certifications.expiry_date'},
{$match:{
dateDifference:{$lte: new Date(date10).toJSON()}
}
}
)https://stackoverflow.com/questions/48056664
复制相似问题