Reputation: 493
I have the following Record in Mongo Database
{
"_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")
}
}
I would like to Filter aggregate with $match equals to currDate. i am using the below query in mongoose but i didn't get any result with query. something is wrong with method or query. but when i run this query directly in mongodb i get the correct result. Need help in this.
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"});
}
);
Upvotes: 1
Views: 2203