Database

[{comment:{text_sentiment:"positive",topic:"A"}},/** DOC-1*/{comment:{text_sentiment:"negative",topic:"A"}},/** DOC-2*/{comment:{text_sentiment:"positive",topic:"B"}}]

Query

db.collection.aggregate([{$match:{/**_id: "xyz",*/"comment.topic":{$exists:1},}},{$group:{_id:"$comment.topic",total:{$sum:1},text_sentiments:{$push:"$comment.text_sentiment"}}},{$project:{topic:"$_id",topicOccurance:"$total",sentiment:{"positive":{$size:{$filter:{input:"$text_sentiments",cond:{$eq:["$$this","positive"]}}}},"negative":{$size:{$filter:{input:"$text_sentiments",cond:{$eq:["$$this","negative"]}}}},"neutral":{$size:{$filter:{input:"$text_sentiments",cond:{$eq:["$$this","neutral"]}}}},}}},{$sort:{"topicOccurance":-1}}])

Result