Database

[{_id:1,parentId:1,"stats":{"type":{"a":{"n:1":2,"n:2":2},"b":{"n:1":2,"n:2":1,"n:3":1},"c":{"n:5":4}}},time:ISODate("2021-10-12T05:00:00Z")},{_id:2,parentId:1,"stats":{"type":{"a":{"n:1":1,},"b":{"n:1":2,"n:2":3,"n:3":4},"c":{"n:4":2}}},time:ISODate("2021-10-12T06:00:00Z")},{_id:3,parentId:2,"stats":{"type":{"a":{"n:1":3,},"b":{"n:2":5,"n:3":7},"c":{"n:1":1,"n:5":2}}},time:ISODate("2021-10-13T05:00:00Z")}]

Query

db.collection.aggregate([{$addFields:{values:{$reduce:{input:{$map:{input:{"$objectToArray":"$stats.type"},as:"typeObj",in:{"$objectToArray":"$$typeObj.v"},}},initialValue:[],in:{"$concatArrays":["$$this","$$value"]}}}}},{$unwind:"$values"},{$group:{_id:{parentId:"$parentId",key:"$values.k"},value:{$sum:"$values.v"},time:{$first:"$time"}}},{$group:{_id:"$_id.parentId",values:{$push:{k:"$_id.key",v:"$value"}},time:{$first:"$time"}}},{$replaceRoot:{newRoot:{"$mergeObjects":[{parentId:"$_id"},{"$arrayToObject":"$values"},{year:{$year:"$time"}},{month:{$month:"$time"}},{day:{"$dayOfMonth":"$time"}},]}}}])

Result