I have data in the following format:
{ "__v" : 0, "_id" : ObjectId("12367687"), "xyzId" : "ADV_ID", "date" : ISODate("2013-08-19T10:58:21.473Z"), "gId" : "987654", "type" : "checks" }
For the above data, I have to build a graph for daily, weekly, monthly and yearly data using the created_on field and counting for the type field. I have the following query that works partially.
db.trackads.aggregate( {$match : {"gId" : "987654",type : 'checks'}}, { $group : { _id : { "day" : {"$week" : "$date"}},cnt : {"$sum" : 1}}});
Result:
{ "result" : [ { "_id" : { "day" : 34 }, "cnt" : 734 }, { "_id" : { "day" : 33 }, "cnt" : 349 } ], "ok" : 1 }
But with the query above I donβt get the results of dates (no week) when the number for "type" = hits is 0. How do I change the mongo query to get the results for count 0 ???
source share