Database
[{"id":"some unique id 1","groupId":"some many to one id mapping",/** ...*/"status":"ACCEPTED","statuses":[{"personId":"some id","status":"ACCEPTED"},{"personId":"some other person","status":"REMOVED"}]},{"id":"some unique id 2","groupId":"some many to one id mapping",/** ...*/"status":"UNPROVISIONED","statuses":[]}]
Query
db.collection.aggregate([{"$set":{"statuses":{"$cond":[{/** if there are statuses.status ...*/"$gt":[{"$size":"$statuses.status"},0]},/** ... use those*/"$statuses.status",/** ... otherwise use status*/["$status"]]}}},{"$unwind":"$statuses"},{"$group":{"_id":{"groupId":"$groupId","status":"$statuses"},"count":{"$count":{}}}}])