Database
[{"_id":ObjectId("6249c77a99e5c26e50736c02"),size:50,brand:"Raymond",color:"Red",},{"_id":ObjectId("622061b73b2eaac4b15d42e4"),brand:"Allen Solly",size:50,color:"Blue"},{"_id":ObjectId("624a700199e5c26e50736c07"),brand:"Van Heusen",size:90,color:"Red"},{"_id":ObjectId("6272e84b6fc62f16bd0f337d"),size:50,brand:"Raymond",color:"Green"},{"_id":ObjectId("622061b73b2eaac4b15d42e9"),brand:"Allen Solly",size:50,color:"Blue"},{"_id":ObjectId("6272e84b6fc62f16bd0f337c"),brand:"Van Gin",size:60,color:"Green"},{"_id":ObjectId("6272e84c6fc62f16bd0f337e"),brand:"Allen Solly",size:70,color:"Black"},{"_id":ObjectId("6272e8546fc62f16bd0f337f"),brand:"Allen Solly",size:70,color:"Blue"},{"_id":ObjectId("6272e8546fc62f16bd0f337d"),brand:"Allen Sir",size:90,color:"Blck"},{"_id":ObjectId("6272e8546fc62f16bd0f337e"),brand:"Allen Solly",size:90,color:"Blue"}]
Query
db.collection.aggregate([{$match:{$or:[{size:{$in:[50,60,70]}},{color:{$in:["Red","Green","Blue"]}},{brand:{$in:["Raymond","Allen Solly","Van Heusen"]}}]}},{"$addFields":{categorizedByColor:{$cond:[{$and:[{$in:["$size",[50,60,70]]},{$in:["$brand",["Raymond","Allen Solly","Van Heusen"]]}]},true,false]},categorizedBySize:{$cond:[{$and:[{$in:["$color",["Red","Green","Blue"]]},{$in:["$brand",["Raymond","Allen Solly","Van Heusen"]]}]},true,false]},categorizedByBrand:{$cond:[{$and:[{$in:["$color",["Red","Green","Blue"]]},{$in:["$size",[50,60,70]]}]},true,false]},productResults:{$and:[{$in:["$color",["Red","Green","Blue"]]},{$in:["$size",[50,60,70]]},{$in:["$brand",["Raymond","Allen Solly","Van Heusen"]]}]},colorGroup:{$cond:[{$in:["$color",["Red","Green","Blue"]]},"$color","OtherColor"]},brandGroup:{$cond:[{$in:["$brand",["Raymond","Allen Solly","Van Heusen"]]},"$brand","OtherBrand"]},sizeGroup:{$cond:[{$in:["$size",[50,60,70]]},{$toString:"$size"},"OtherSize"]}}},{$group:{_id:0,colors:{$push:{$cond:[{$eq:["$categorizedByColor",true]},{k:"$colorGroup",t:"categorizedByColor"},{k:"other",t:"notAllowed"}]}},brands:{$push:{$cond:[{$eq:["$categorizedByBrand",true]},{k:"$brandGroup",t:"categorizedByBrand"},{k:"other",t:"notAllowed"}]}},sizes:{$push:{$cond:[{$eq:["$categorizedBySize",true]},{k:"$sizeGroup",t:"categorizedBySize",},{k:"other",t:"notAllowed",}]}},results:{$push:{$cond:[{$and:[{$eq:["$categorizedBySize",true]},{$eq:["$categorizedByBrand",true]}]},{k:"results",t:"productResults",},{k:"other",t:"notAllowed",}]}}}},{$project:{data:{$concatArrays:["$sizes","$brands","$colors","$results"]}}},{$unwind:"$data"},{$group:{_id:"$data.k",count:{$sum:1},tag:{$first:"$data.t"}}},{$group:{_id:"$tag",data:{$push:{k:"$_id",v:"$count"}}}},{$match:{"_id":{$ne:"notAllowed"}}},{$project:{data:{"$arrayToObject":"$data"}}}])