2
我正在使用MongoDB的聚合管道,以我想要的形式获取我的文档。作为最后一步的汇总,我使用$project
将文档放入最终形式。使用MongoDB项目数组
但我在投影和排列子文档时遇到了麻烦。以下是我目前从aggrgation得到:
{
"_id": "581c8c3df1325f68ffd23386",
"count": 14,
"authors": [
{
"author": {
"author": "57f246b9e01e6c6f08e1d99a",
"post": "581c8c3df1325f68ffd23386"
},
"count": 13
},
{
"author": {
"author": "5824382511f16d0f3fd5aaf2",
"post": "581c8c3df1325f68ffd23386"
},
"count": 1
}
]
}
我想$project
的authors
阵列,这样的回报将是这样的:
{
"_id": "581c8c3df1325f68ffd23386",
"count": 14,
"authors": [
{
"_id": "57f246b9e01e6c6f08e1d99a",
"count": 13
},
{
"_id": "5824382511f16d0f3fd5aaf2",
"count": 1
}
]
}
我将如何去实现呢?
能好心编辑您的问题,包括聚合管道,用于测试一些样本文档? – chridam