Database

[{"date":new Date(),"type":1},{"date":new Date(),"type":1}]

Query

db.collection.aggregate([{$group:{_id:{year:{$dateToString:{format:"%Y",date:"$date"}},typeId:"$type"},count:{$sum:1}}},{$project:{_id:0,years:{$arrayToObject:[[{k:{$toString:"$_id.year"},v:{typeId:"$_id.typeId",count:"$count"}}]]}}}])

Result