I have the following 3 documents in my MongoDB:
[Object_id: "tMSfNq9JR85XDaQe5"date: Sun Dec 07 2014 19:50:21 GMT+0800 (HKT)description: "Test" projectid: "S83NEGHnrefvfASrf"totalseconds: 22200__proto__: Object,
Object_id: "FeyzdMosaXCht8DKK"date: Mon Dec 15 2014 00:00:00 GMT+0800 (HKT)description: "444"projectid: "S83NEGHnrefvfASrf"totalseconds: 3660__proto__: Object,
Object_id: "cCKByxSdQMHAsRKwd"date: Mon Dec 15 2014 00:00:00 GMT+0800 (HKT)description: "555"projectid: "S83NEGHnrefvfASrf"totalseconds: 3660__proto__: Object]
I am trying to run the following aggregate pipeline on it to group the sum of totalseconds
by date
so that the end result will be something like shown below, yet each time I get the result as 3 records exactly just as input 3 documents...can someone please tell me what I might be doing wrong / missing here? Thanks
var pipeline = [
{$group:
{_id:{"projectId":"$projectid", "date":"$date"},
totalHrs:{$sum:"$totalseconds"}
}
}
];
{ "Date":"Sun Dec 07 2014 19:50:21 GMT+0800 (HKT)",
"totalseconds": "22200"
},
{ "Date":"Sun Dec 15 2014 00:00:00 GMT+0800 (HKT)",
"totalseconds": "7320"
}