Database

[{_id:ObjectId("5a934e000102030405000000"),name:"john",sex:"male",hobbies:["football","tennis","swimming"]},{_id:ObjectId("5a934e000102030405000001"),name:"betty",sex:"female",hobbies:["football","tennis"]},{_id:ObjectId("5a934e000102030405000002"),name:"frank",sex:"male",hobbies:["football","tennis"]}]

Query

db.collection.aggregate([{$unwind:"$hobbies"},{$group:{_id:{sex:"$sex",hobbies:"$hobbies"},count:{$sum:1},totalIds:{$addToSet:"$_id"}}},{$group:{_id:"$_id.sex",hobbies:{$push:{k:"$_id.hobbies",v:"$count"}},totalIds:{$push:"$totalIds"}}},{$set:{hobbies:{$arrayToObject:"$hobbies"},totalIds:{$reduce:{input:"$totalIds",initialValue:[],in:{$concatArrays:["$$value","$$this"]}}}}},{$set:{count:{$size:{$setIntersection:"$totalIds"}},totalIds:"$$REMOVE"}}])

Result