I\'ve got documents that look like this:
{
\"_id\" : \"someuniqueeventid\",
\"event\" : \"event_type_1\",
\"date\" : ISODate(\"2014-01-14T00:00:0
With MongoDb 3.4.4 and newer, you can leverage the use of $arrayToObject operator to get the counts. You would need to run the following aggregate pipeline:
db.data.aggregate([
{
"$group": {
"_id": {
"event": "$event",
"day": { "$substr": [ { "$dayOfWeek": "$date" }, 0, -1 ] }
},
"count": { "$sum": 1 }
}
},
{
"$group": {
"_id": "$_id.event",
"counts": {
"$push": {
"k": "$_id.day",
"v": "$count"
}
}
}
},
{
"$project": {
"counts": { "$arrayToObject": "$counts" }
}
}
])