Database

[{_id:ObjectId("5fba17c1c4566e57fafdcd71"),"parent_comment_id":ObjectId("5fba17c1c4566e57fafdcd7e"),"comment":"fdfda",replies:2},{_id:ObjectId("5fba17c1c4566e57fafdcd72"),"parent_comment_id":ObjectId("5fba17c1c4566e57fafdcd7e"),"comment":"sdfdsf",replies:5},{_id:ObjectId("5fba17c1c4566e57fafdcd7e"),"parent_comment_id":null,"comment":"sgfdghfdhh",replies:4},{_id:ObjectId("5fba17c1c4566e57fafdcd73"),"parent_comment_id":ObjectId("5fba17c1c4566e57fafdcd7a"),"comment":"loklk",replies:1},{_id:ObjectId("5fba17c1c4566e57fafdcd7a"),"parent_comment_id":null,"comment":"ssss",replies:22},]

Query

db.collection.aggregate([{"$addFields":{parent_comment_id:{"$ifNull":["$parent_comment_id","$_id"]}}},{"$group":{_id:"$parent_comment_id","comment":{"$push":{"$cond":[{"$eq":["$parent_comment_id","$_id"]},"$comment","$$REMOVE"]}},replies:{"$count":{}}}},{$project:{comment:{"$arrayElemAt":["$comment",0]},replies:1}}])

Result