我在Mongo数据库中有以下记录
{
"_id" : ObjectId("54a0d4c5bffabd6a179834eb"),
"is_afternoon_scheduled" : true,
"employee_id" : ObjectId("546f0a06c7555ae310ae925a"),
"currDate" : ISODate("2014-12-28T18:30:00Z"),
"modified_date" : ISODate("2014-12-29T04:12:53.677Z"),
"modified_by" : ObjectId("541a9c223416b36f67cfbfe8"),
"__v" : 0,
"manager_schedule" : {
"afternoon_schedule_details" : {
"event" : ObjectId("54507897cecff53914c82b6d"),
"is_afternoon_scheduled" : true
},
"modified_by" : ObjectId("541a9c223416b36f67cfbfe8"),
"modified_date" : ISODate("2014-12-29T04:13:00.432Z")
}
}
我想使用$ match equals过滤聚合到currDate。我在mongoose中使用以下查询,但我没有得到任何查询结果。方法或查询有问题。但是当我直接在mongodb中运行此查询时,我得到了正确的结果。需要帮助。
var mongoose = require("mongoose");
var empid = mongoose.Types.ObjectId("54a0d4c5bffabd6a179834eb");
Availability.aggregate()
.match( { employee_id : empid, currDate: "2014-12-28T18:30:00Z" } )
.group({_id : "$employee_id",count: { $sum: 1 }})
.exec(function (err, response) {
if (err) console.log(err);
res.json({"message": "success", "data": response, "status_code": "200"});
}
);
答案 0 :(得分:1)
使用此:
currDate: new Date("2014-12-28T18:30:00Z")