Database

[{_id:"xxxsdsdsds",category:"food",sub_category:"bread",manufacturer:"cooper_inc",brand_name:"cooper_breads",cost:45,shop:"4AM_Mart"},{_id:"ddsfdfdggf",category:"food",sub_category:"cheese",manufacturer:"cooper_inc",brand_name:"cooper_cheese",cost:60,shop:"4AM_Mart"},{_id:"dsdsfdfdffdf",category:"food",sub_category:"bread",manufacturer:"jason_inc",brand_name:"jason_breads",cost:56,shop:"4AM Mart"},{_id:"wdsfdfdfdgg",category:"food",sub_category:"cheese",manufacturer:"jason_inc",brand_name:"jason_breads",cost:54,shop:"4AM_Mart"},{_id:"dfddgfgfgf",category:"food",sub_category:"bread",manufacturer:"yeoman_inc",brand_name:"yeoman_breads",cost:34,shop:"4AM_Mart"},{_id:"dfdsflkdsfjdsfjd",category:"food",sub_category:"cheese",manufacturer:"yeoman_inc",brand_name:"yeoman_cheese",cost:80,shop:"4AM_Mart"},{_id:"dfdfnjdsnfdnfnfds",category:"beverage",sub_category:"energy_drink",manufacturer:"red_bull",brand_name:"red_bull_energy_drink",cost:50,shop:"4AM_Mart"},{_id:"xxxsdsdsdsss",category:"food",sub_category:"bread",manufacturer:"cooper_inc",brand_name:"cooper_breads",cost:45,shop:"downey_mart"},{_id:"ddsfdfdggfsds",category:"food",sub_category:"cheese",manufacturer:"cooper_inc",brand_name:"cooper_cheese",cost:60,shop:"downey_mart"},{_id:"dsdsfdfdffdfssds",category:"food",sub_category:"bread",manufacturer:"jason_inc",brand_name:"jason_breads",cost:56,shop:"downey_mart"},{_id:"wdsfdfdfdggdsdsd",category:"food",sub_category:"cheese",manufacturer:"jason_inc",brand_name:"jason_breads",cost:54,shop:"downey_mart"},{_id:"dfddgfgfgfsdsfsds",category:"food",sub_category:"bread",manufacturer:"yeoman_inc",brand_name:"yeoman_breads",cost:34,shop:"downey_mart"},{_id:"dfdsflkdsfjdsfjddsfdgfg",category:"food",sub_category:"cheese",manufacturer:"yeoman_inc",brand_name:"yeoman_cheese",cost:80,shop:"downey_mart"}]

Query

db.collection.aggregate([{"$match":{"shop":"4AM_Mart"}},{"$group":{_id:"$shop",totalAmount:{$sum:{"$cond":[{"$ne":["$manufacturer","cooper_inc"]},"$cost",0]}},singleAmount:{$sum:{$cond:[{"$eq":["$manufacturer","cooper_inc"]},"$cost",0]}}}},{"$project":{result:{"$sum":["$totalAmount","$singleAmount"]}}}])

Result