所以我在我的 MongoDB 实例中有这个结构。
{
"post_body": "test",
"author": "test1",
"comments":[
{
"comment_body": "comment test",
"comment_author": "test2",
"replies": [
{
"reply_body": "reply test1",
"reply_author": "test3"
},
{
"reply_body": "reply test2",
"reply_author": "test2"
}
]
}
]
}
我想获得评论+回复的总数。
所以我想要的输出应该是
{
"post_body": "test"
"author": "test1",
"comment_count": 3
}
到目前为止,仅使用$project
仅返回评论总数。我想得到评论+回复的总数