0
之间你好请帮我解决这个问题猫鼬查询日期时间
我需要在猫鼬 2016-09-25T00之间在查询日期时间数据:00 1:10.000 + 07:00至2016-09- 25T01:00:10.000 + 07:00
上robomongo我用这个查询它的工作找到
db.getCollection('positions').find({unit_id:"863835025684908",
utc_ts : {
$gte: ISODate("2016-09-25T00:00:10.000+07:00"),
$lt: ISODate("2016-09-25T01:00:10.000+07:00")
}
})
我造成
{
"_id" : ObjectId("57e6bd10fa10a661c4145870"),
"updated_at" : ISODate("2016-09-25T00:51:12.673+07:00"),
"created_at" : ISODate("2016-09-25T00:51:12.673+07:00"),
"unit_id" : "863835025684908",
"utc_ts" : ISODate("2016-09-25T00:51:10.000+07:00"),
"recv_utc_ts" : ISODate("2016-09-25T00:51:12.000+07:00"),
"lat" : 14.127961,
"lon" : 100.621365
}
但是,当我对猫鼬查询我用这个
var startDate = moment(req.params.startTime).add('hours',7); //req.params.startTime = 2016-09-25 00:00:00
var endDate = moment(req.params.endTime).add('hours',7); //req.params.endTime = 2016-09-25 01:00:00
//Find
Positions.find({
unit_id: req.params.unit_id,
utc_ts: {
$gt: new Date(startDate).toISOString(),
$lt: new Date(endDate).toISOString()
}
}, function(err, positions) {
if (err) {
return err
}
else {
//console.log(positions);
res.json(positions);
}
});
我看到猫鼬调试表演
Mongoose: positions.find({ utc_ts: { '$gt': new Date("Sat, 24 Sep 2016 00:51:10 GMT"), '$lt': new Date("Sat, 24 Sep 2016 01:08:36 GMT") }, unit_id: '863835025684908' }, { fields: undefined })
然后我从查询
是的,我试过,但还是空的数据 – Wetrue
那么你可以尝试'UTCOFFSET(“+ 0700”)''的功能momentjs'。我也更新了代码 –
我用你的编辑代码仍然不行。 – Wetrue