here i have create one query for the show count date wise in the chart. and i have used mongodb. and i have one object and in the object store multiple data and separate with one value Action. i want to show count date wise Action like Comment,like both action count want show. right now i am just show comment count. i want also get like count. here below i have listed my object and query.
here this is my array of the 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: '03-10-2017', count: 1 },
{ _id: '04-10-2017', count: 2 },
{ _id: '05-10-2017', count: 2 },
{ _id: '06-10-2017', count: 2 } ]
my excepted o/p =>
[ { _id: '03-10-2017', count: 1 ,likecount:0},
{ _id: '04-10-2017', count: 2 ,likecount:0},
{ _id: '05-10-2017', count: 2,likecount:0 },
{ _id: '06-10-2017', count: 2,liekcount:1},
this is my query =>
InstaAc.aggregate([
{
"$match": {
"_id": ObjectId("595e3b2033961713940442cf"),
"History.datetime": {
"$lte": 1507529239000, "$gte": 1507012285558
}
}
},
{
"$unwind": "$History"
},
{
"$match": {
"History.datetime": {
"$lte": 1507529239000, "$gte": 1507012285558
},
"History.Action": {
$eq: "comment"
}
}
},
{
"$addFields": {
"History.datetime": {
"$add": [new Date(0), "$History.datetime"]
}
}
},
{
"$group": {
"_id": {
"$dateToString": {
"format": "%d-%m-%Y",
"date": "$History.datetime"
}
},
"count": {
"$sum": 1
}
}
},
{
"$sort": {
"_id": 1
}
}
]).exec(function (err, data) {
if (err) {
console.log(err);
}
else {
console.log(data);
}
})
any one how can do that then please let me know.