Database

[{"categoryCode":"categoryCode1","categoryName":"categoryName1","cat_id":"A"},{"categoryCode":"categoryCode1","categoryName":"categoryName1","cat_id":"B"},{"categoryCode":"categoryCode2","categoryName":"categoryName2","cat_id":"C"}]

Query

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

Result