I am trying to setup a merge with MongoDb for 2 collections. Collections are nested. I have 2 collections:
1/ Options
{
"_id": {
"$oid": "58c9866ff36d286bfca335b4"
},
"design": {
"mainPage": {
"imgRight": "58cc750ddc238d05dd6ca525",
"imgLeft": "58cc750ddc238d05dd6ca526"
}
}
}
2/ Forms
{
"_id": {
"$oid": "58cc750ddc238d05dd6ca525"
},
"imagePath": "logo.png"
}
How can I do an aggregate to get this result:
{
"_id": {
"$oid": "58c9866ff36d286bfca335b4"
},
"design": {
"mainPage": {
"imgRight": "58d07571d9d39e50166b5b3d",
"form_docs" : {
"imagePath": "logo.png"
}
"imgLeft": "58cc750ddc238d05dd6ca526",
"form_docs" : {
"imagePath": ""
}
}
}
}
I am trying with the snippet below, but it doesn't work:
Options.aggregate([
{ "$unwind": "$design" },
{ "$unwind": "$design.mainPage" },
{
$lookup:
{
from: "forms",
localField: "design.mainPage.imgLeft",
foreignField: "_id",
as: "form_docs"
}
}
])