Database

[{metaData:{survey:ObjectId("62206ea0b31be3535abac547")},answers:{"question1":"a","question2":"b","question3":["a","c"],"question4":3},createdAt:ISODate("2022-03-03T07:30:40.517Z")},{metaData:{survey:ObjectId("62206ea0b31be3535abac547")},answers:{"question1":"a","question2":"b","question3":["a","c"],"question4":2},createdAt:ISODate("2022-03-03T07:30:40.518Z")},{metaData:{survey:ObjectId("62206ea0b31be3535abac547")},answers:{"question1":"b","question2":"c","question3":["b"],"question4":1},createdAt:ISODate("2022-03-03T07:30:40.518Z")}]

Query

db.collection.aggregate([{$match:{}},{$project:{answers:{$objectToArray:"$answers"}}},{$unwind:"$answers"},{$set:{"answers.type":{$switch:{branches:[{case:{$isArray:"$answers.v"},then:"multi"},{case:{$eq:[{"$type":"$answers.v"},"string"]},then:"radio"},{case:{$isNumber:"$answers.v"},then:"avg"}],default:"other"}}}},{$unwind:"$answers.v"},{$group:{_id:"$answers",c:{$sum:1}}},{$group:{_id:"$_id.k",type:{$first:"$_id.type"},v:{$push:{k:{$toString:"$_id.v"},v:"$c"}}}},{$group:{_id:"$type",v:{$push:{k:"$_id",v:{$arrayToObject:"$v"}}}}},{$group:{_id:null,v:{$push:{k:"$_id",v:{$arrayToObject:"$v"}}}}},{$set:{v:{$arrayToObject:"$v"}}},{$replaceWith:"$v"},{$set:{avg:{$arrayToObject:{$map:{input:{$objectToArray:"$avg"},as:"s",in:{k:"$$s.k",v:{$avg:{$map:{input:{$objectToArray:"$$s.v"},as:"x",in:{$multiply:[{$toInt:"$$x.k"},"$$x.v"]}}}}}}}}}}])

Result