我正在尝试从特定时间间隔内具有某些时间属性的mongoDB
中提取数据。过滤器由请求查询字符串定义:
var getLessonByParams = function (req, res, next){
console.log(req.query.timeFrom);
if(req.query.timeFrom !== undefined){
req.query.timeFrom = {$gte: req.query.timeFrom};
}
if(req.query.timeTo !== undefined){
req.query.timeTo = {$lte: req.query.timeTo};
}
console.log(req.query);
LessonModel.find(req.query, function (err, lessons){
if(!err){
res.status(200).json(lessons);
}
else{
return next(errorHelper(err));
}
});
};
但是有些东西显然是错误的,因为它在我指定的时间之前返回数据,并且不返回它应该返回的一些记录。有什么想法吗?
编辑:
传入查询变量:
2015-08-01T01:15:00.000Z
替换gte
后的查询:
{ timeFrom: { '$gte': Sat Aug 01 2015 03:15:00 GMT+0200 (CEST) } }
猫鼬输出:
Mongoose: lessons.find({ timeFrom: { '$gte': new Date("Sat, 01 Aug 2015 01:15:00 GMT") } }) { fields: undefined }
我正在处理的文件:
{
"_id" : ObjectId("55d1db90daea17d3e90a3c4d"),
"timeFrom" : ISODate("2015-08-01T01:15:00.000Z"),
"timeTo" : ISODate("2015-08-01T02:15:00.000Z")
}
{
"_id" : ObjectId("55d1ee1cdaea17d3e90a3c53"),
"timeFrom" : ISODate("2015-08-01T01:45:00.000Z"),
"timeTo" : ISODate("2015-08-01T02:30:00.000Z")
}
{
"_id" : ObjectId("55d73b10de2699c615778bd8"),
"timeTo" : "2015-08-02T06:45:00.000Z",
"timeFrom" : "2015-08-02T05:15:00.000Z",
}