I am fairly new to MongoDB and I came across the $replaceRoot(aggregation) which I need to output the document the way I need it.
Document Schema
{
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"
}
}
]
}
Wanted Output
{
name: "Apple",
image: "",
is_fruit: true,
other: [
{
text: "An apple a day keeps the doctor away"
},
...
]
}
i.e: To make quotes field as the root of the other array and not the root of entire document.
Thank you.
