Database

[{"technology":"NEPTUNE","environment":"PROD"},{"technology":"NEPTUNE","environment":"NONPROD"},{"technology":"ELASTIC","environment":"PROD"},{"technology":"ELASTIC","environment":"NONPROD"},]

Query

db.collection.aggregate([{"$group":{"_id":"$technology","PROD":{"$sum":{"$cond":{"if":{"$eq":["$environment","PROD"]},"then":1,"else":0}}},"TOTAL":{"$sum":1}}},{"$project":{"_id":0,"technology":"$_id","TOTAL":1,"PROD":1,"NONPROD":{"$subtract":["$TOTAL","$PROD"]}}}])

Result