Database

[{"cat_id":1,"categoryCode":"categoryCode1","categoryName":"categoryName1","cat_type":"A"},{"cat_id":2,"categoryCode":"categoryCode1","categoryName":"categoryName1","cat_type":"A"},{"cat_id":3,"categoryCode":"categoryCode2","categoryName":"categoryName2","cat_type":"C"},{"cat_id":4,"categoryCode":"categoryCode3","categoryName":"categoryName3","cat_type":"A"}]

Query

db.collection.aggregate([{$group:{_id:{"categoryCode":"$categoryCode","categoryName":"$categoryName"},"cat_count":{$sum:{$cond:[{$eq:["$cat_type","A"]},1,0]}}}},{$project:{"_id":0,"categoryCode":"$_id.categoryCode","categoryName":"$_id.categoryName","cat_count":"$cat_count"}}])

Result