I'm working on a school project and I need to join the subject document with content documents on contentId. However, I can't use mongoose because I'm working with a stack provided by the school. Here's an example to explain my problem:
Example subject document:
{
_id: ObjectId('000000000000000000000100')
name: "My subject"
description: "Lorem ipsum..."
language: "en",
topics: [
{
id: ObjectId('000000000000000000000200'),
name: "The first topic",
description: "Lorem ipsum...",
content: [
{
contentId: ObjectId('000000000000000000000300'),
visibility: true,
},
{
url: "stackoverflow.com",
title: "Stack Overflow",
type: "website"
}
]
}
]
}
Example content document:
{
_id: ObjectId('000000000000000000000300'),
title: "Example content",
description: "Example course in MongoDB",
url: "http://example.com/believe/apparatus.php?birthday=bed&boot=bead"
type: "other"
}
I need the result of the aggregation to look like this:
{
_id: ObjectId('000000000000000000000100')
name: "My subject"
description: "Lorem ipsum..."
language: "en",
topics: [
{
id: ObjectId('000000000000000000000200'),
name: "The first topic",
description: "Lorem ipsum...",
content: [
{
_id: ObjectId('000000000000000000000300'),
title: "Example content",
description: "Example course in MongoDB",
url: "http://example.com/believe/apparatus.php?birthday=bed&boot=bead"
type: "other"
visibility: true,
},
{
url: "stackoverflow.com",
title: "Stack Overflow",
type: "website"
}
]
}
]
}
I have tried some $unwind and $lookup combinations but none of them returned the correct result.
Is there a way to do this without using mongoose? Thank you.