Database

db={"items":[{"shopId":ObjectId("6043adb043707c034d5363b6"),/** <- this is mongodb id*/"shopItems":[{itemId:ObjectId("612fb15bc5ec82033a11793a"),/**mongodbiditemCount: 5,*/colorId:ObjectId("603e061ee805140334e79451"),itemCount:5},]},{"shopId":ObjectId("604c776763c302032e610347"),"shopItems":[{itemId:ObjectId("6043adb043707c034d5363b6"),/**mongodbiditemCount: 5,*/colorId:ObjectId("60533cafdb90f40335de3b2a"),itemCount:3},{itemId:ObjectId("61d70bdf1d59792259a733b5"),/**mongodbiditemCount: 3,*/colorId:ObjectId("603e061ee805140334e79451"),itemCount:77}]},],"shops":[{"_id":ObjectId("6043adb043707c034d5363b6"),"shopName":"shop1"},{"_id":ObjectId("604c776763c302032e610347"),"shopName":"shop2"},],"colors":[{"_id":ObjectId("603e061ee805140334e79451"),"colorName":"red"},{"_id":ObjectId("60533cafdb90f40335de3b2a"),"colorName":"green"},],"products":[{"_id":ObjectId("612fb15bc5ec82033a11793a"),"name":"product 1"},{"_id":ObjectId("6043adb043707c034d5363b6"),"name":"product 2"},{"_id":ObjectId("61d70bdf1d59792259a733b5"),"name":"product 3"}],}

Query

db.items.aggregate([{"$match":{}/** <-- Highly recommend you to use match due to the complexity of this query*/},{$group:{_id:0,data:{$push:{shopId:"$shopId",shopItems:"$shopItems"}},shopIds:{"$push":{shopId:"$shopId","count":0}}}},{$unwind:"$data"},{$unwind:"$data.shopItems"},{$group:{_id:{itemId:"$data.shopItems.itemId",colorId:"$data.shopItems.colorId"},data:{$push:{shopId:"$data.shopId",count:"$data.shopItems.itemCount"}},existing:{$push:{shopId:"$data.shopId","count":0}},shopIds:{$first:"$shopIds"}}},{"$addFields":{"missing":{"$setDifference":["$shopIds","$existing"]}}},{$project:{data:{$concatArrays:["$data","$missing"]}}},{$unwind:"$data"},{$sort:{"data.shopId":1}},{$group:{_id:"$_id",counts:{/** here you can change this key*/$push:"$data"},totalCount:{$sum:"$data.count"}/** if you want it*/}}])

Result