用猫鼬和日期查询 [英] Querying with mongoose and dates

查看:67
本文介绍了用猫鼬和日期查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出如何对猫鼬进行特定查询. 我在mongodb中有这样的内容:

I'm trying to find out how to do an specific query with mongoose. I have in mongodb something like this:

{ "_id" : 1, "modificationDate" : ISODate("2013-06-26T18:57:30.012Z") }
{ "_id" : 2, "modificationDate" : ISODate("2013-06-26T18:57:35.012Z") }

我想获取所有实际日期和modificationDate之间的差异大于5天的对象.

I want to obtain all the objects where the difference between the actual date and modificationDate is greater than 5 days.

推荐答案

计算5天的截止时间,然后使用$lt运算符和计算出的截止值执行find:

Calculate the 5-days-old cutoff time and then perform a find using the $lt operator and the calculated cutoff:

var cutoff = new Date();
cutoff.setDate(cutoff.getDate()-5);
MyModel.find({modificationDate: {$lt: cutoff}}, function (err, docs) { ... });

这篇关于用猫鼬和日期查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆