我有以下文件:
"content": [
{
"_id": "5dbef12ae3976a2775851bfb",
"name": "Item AAA",
"itemImages": [
{
"_id": "5dbef12ae3976a2775851bfd",
"imagePath": "https://via.placeholder.com/300",
"imageTitle": "Test 300"
},
{
"_id": "5dbef12ae3976a2775851bfc",
"imagePath": "https://via.placeholder.com/250",
"imageTitle": "Test 250"
}
]
}
,我想知道是否有一种方法可以只返回数组中的数据,但带有“名称”和文档“ main _id”,以便结果集为
"itemImages": [
{
"_id": "5dbef12ae3976a2775851bfb",
"name": "Item AAA",
"imagePath": "https://via.placeholder.com/300",
"imageTitle": "Test 300"
},
{
"_id": "5dbef12ae3976a2775851bfb",
"name": "Item AAA",
"imagePath": "https://via.placeholder.com/250",
"imageTitle": "Test 250"
}
]
我尝试使用mongodb find和聚合函数,但都没有帮助检索上述结果。谢谢您的帮助
答案 0 :(得分:1)
您应该能够通过聚合获得想要的东西。
您需要:
这可能看起来像:
declare -p var