Database
[{"key":"software"},{"key":"hardware"},{"key":"software"},{"key":"test"},{"key":"tested"}]
Query
db.collection.aggregate([{"$project":{key:{"$switch":{"branches":[{"case":{"$eq":["$key","software"]},"then":"software"},{"case":{"$eq":["$key","hardware"]},"then":"hardware"}],default:"other"}}}},{"$group":{"_id":"$key","count":{"$sum":1}}},])