【发布时间】:2019-12-05 16:57:39
【问题描述】:
我是 MongoDB 的新手,我遇到了 $replaceRoot(aggregation),我需要以我需要的方式输出文档。
文档架构
{
name: "Apple",
image: "",
is_fruit: true,
other: [
{
url: "",
quotes: { // saved as ObjectId and is then lookedup or populated
text: "An apple a day keeps the doctor away"
}
}
]
}
想要的输出
{
name: "Apple",
image: "",
is_fruit: true,
other: [
{
text: "An apple a day keeps the doctor away"
},
...
]
}
即:将引号字段作为另一个数组的根而不是整个文档的根。
谢谢。
【问题讨论】:
-
我真的不明白你在这里想要达到的目标。您是否试图限制数组内返回字段的数量?或者“url”和“quotes”字段在哪里?
标签: mongodb aggregation-framework