我有一个名为" listenedMessage"在我的MongoDb中它有一个名为" timeReceived" 如何根据" timeReceived"找到所有超过一年的记录?场?
答案 0 :(得分:1)
基于@Puneet Singh的评论,我找到了一个解决方案,该解决方案检索所有记录的“timeReceived”字段超过特定月份。
function addMonths(date, months) {
date.setMonth(date.getMonth() + months);
return date;
}
db.listenedMessage.find({"timeReceived" : {$lt: addMonths(new Date(), -1)}}).count(); //this will give all the records having timeReceived field older than a month from today