Database
[{produce:"potato","variety":"abc","state":"PA"},{produce:"potato","variety":"abc","state":"PA"},{produce:"potato","variety":"def","state":"IA"},{produce:"potato","variety":"def","state":"IA"},{produce:"potato","variety":"abc","state":"DA"},{produce:"potato","variety":"abc","state":"DA"},{produce:"potato","variety":"def","state":"DA"},{produce:"potato","variety":"abc","state":"IA"}]
Query
db.collection.aggregate([{"$group":{"_id":{"variety":"$variety","state":"$state"},"count":{"$sum":1}}},{"$group":{"_id":"$_id.variety","states":{"$push":{"k":"$_id.state","v":"$count"}}}},{"$addFields":{"states":{"$arrayToObject":"$states"}}}])