Hi
I have the following schema in my mongodb:
Post Schema
{
_id: ObjectId,
text: string,
owner: ObjectId,
comments: {
count: number,
entities: [
{
owner_id: ObjectId,
replies: {
count: number, entities: [ { owner_id: ObjectId } ]
}
}
]
}
}
Like you can see I have here post and inside of it there is an object called comments witch has a number called count representing the count of comments and an array of comment entities.
the comment entity has an owner_id
field and replies object which is very similar to comments object has a count and entities array which containing an owner_id field inside of each element.
my problem here is that i want to populate the owners inside the post and the comments and the replies.
i found a way of doing that by using multiple $unwind
and $lookup
and $group
which tends to be so complicated
so what is the easiest way of doing that user aggregation pipeline.
Thanks.