I want to go show data in the chart using date wise last 7 days date with data.and i am using this for database is mongodb and working in nodejs. i have create also one query for that generate date wise count but i am not getting success. i am getting count whole date wise. not apply group by on date. and in the database i have store datetime in timestamp so i need to here work with only date.here i have also generate last 7 day and generate lastdate in the timestamp and apply one condition lastdate greater than or equal date to get count. so here i have listed my code and object so any see and have the idea how can fix it then please let me know.
This is my array of object =>
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c28"),
"Action" : "Comment",
"datetime" : 1507099928000 // 4th oct 2017 convert date just for info here write
},
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c28"),
"Action" : "Comment",
"datetime" : 1507099928000 // 4th oct 2017 convert date just for info here write
}
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c30"),
"Action" : "Comment",
"datetime" : 1507186328000 // 5th oct 2017 convert date just for info here write
}
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c28"),
"Action" : "Comment",
"datetime" : 1507193528000 // 5th oct 2017 convert date just for info here write
},
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c28"),
"Action" : "Comment",
"datetime" : 1507279928000 // 6th oct 2017 convert date just for info here write
}
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c30"),
"Action" : "Comment",
"datetime" : 1507020728000 // 3th oct 2017 convert date just for info here write
}
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c28"),
"Action" : "Comment",
"datetime" : 1507279928000 // 6th oct 2017 convert date just for info here write
},
{
"_id" : ObjectId("578fa05a7391bb0d34bd3c28"),
"Action" : "like",
"datetime" : 1507279928000 // 6th oct 2017 convert date just for info here write
}
my current o/p=>
{ _id: null, count: 8 }
my expecated o/p =>
{ _id: 3-10-2017, count: 1,Action = "comment" }
{ _id: 4-10-2017, count: 2,Action = "comment" }
{ _id: 5-10-2017, count: 2,Action = "comment" }
{ _id: 6-10-2017, count: 2,Action = "comment" }
here this is my query =>
var lastdate = 1507012285558; // this is last date 3rd oct 2017 now here to greate than date find and get count
InstaAc.aggregate([
{
"$match": {
"_id": ObjectId("595e3b2033961713940442cf"),
"History.datetime": {
"$gte": lastdate
}
}
},
{
"$unwind": "$History"
},
{
"$match": {
"History.datetime": {
"$gte": lastdate
},
"History.Action": {
$eq: "comment"
}
}
},
{
"$group": {
"_id": "$_id",
"count": {
"$sum": 1
},
"History": {
"$push": "$History"
}
}
},
{
"$sort": {
"_id": 1
}
}
]).exec(function (err, data) {
if (err) {
console.log(err);
}
else {
console.log(data[0]);
}
})