我正在使用以下查询来获取数据库中每个帖子的最新评论:
db.comments.aggregate([
{
"$match": {
"post_id": {
"$in": [ObjectId("52c5ce24dca32d32740c1435"), ObjectId("52c5ce24dca32d32740c15ad")]
}
}
},
{
"$sort": {"_id": -1}
},
{
"$group": {
"_id": "$post_id",
"lastComment": {
"$first": "$_id"
}
}
}
])
Run Code Online (Sandbox Code Playgroud)
我希望它返回整个评论的文档,但它只返回_id每个文档的字段.那么将所有最新评论作为整个文档(或至少包括其他一些领域)的正确方法是什么?