i wanna go show daily count show in the chart using mongodb. i am first generate today to last 5 days date in the chart. and in the my mongodb i have the object store daily to daily. show i now i want to get count date wise only using group by but i have no idea how can use group by. i have write one query but this query return all the object and does't return any count so any one have idea how can do that please tell me. i have one date also so i want to start count using this date to equal or greater than.
here this is my query =>
app.get(prefix + '/GetAnalyticsByUserId', function (req, res, next) {
var instaid = req.query.instaid;
var lastdate = req.query.lastdate; // this is my date in the timestamp i want to using this equal or greater date and count
InstaAc.aggregate(
{ $match: { _id: ObjectId("595f6bcdeb3db12064f26336") } },
{ $unwind: '$History' },
{ $match: { 'History.Action': { $eq: "Comment" } } },
{ $match: { 'History.datetime': { $gte: "datetime" } } },
{ $group: { _id: '$_id', History: { $push: '$History' } } }).exec(function (err, data) {
if (err) {
console.log(err); res.send(err)
}
else {
console.log(data);
res.send(data);
}
})
});
this is my array in the db =>
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c28"),
"Action" : "Comment",
"datetime" : 1507549688000
},
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c28"),
"Action" : "Comment",
"datetime" : 1507553288000
}
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c30"),
"Action" : "Comment",
"datetime" : 1507466888000
}
my expecated o/p =>
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c28"),
"Action" : "Comment",
"datetime" : 1507549688000
"count":2
},
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c30"),
"Action" : "Comment",
"datetime" : 1507466888000
"count":1
}
here above i have just posted some object like this more object is store in the db so i want to get count using group by date.any one know how can do that then please let me.