question, answer and profile modals
question = {
_id: "00000",
question: "",
category: "gaming"
}
answer = {
_id: "xyz",
answer: "some answer",
questionId: "00000",
userID: "11111"
}
profile = {
_id: "11111",
name: "alex",
}
what i want to achieve:
{
_id: "00000",
question: "",
category: "gaming",
usersAnswered: [
{ _id: "xyz",
answer: "some answer",
questionId: "00000",
userID: {
_id: "11111",
name: "alex",
}
}
]
}
i want to populate the userID
field which we get from $lookup
question
.aggregate([
{
$match: {
category: "gaming",
},
},
{
$lookup: {
from: "answers",
localField: "_id",
foreignField: "questionID",
as: "usersAnswered",
},
},
])
what should be done to further populate the userID field using $lookup i guess.
Just a bit new to aggregation framework, been using mongoose to get the job done but then this situation came up and had to integrate a field from another collection in question model i.e. usersAnswered
so i am learning aggregation framework it gets a bit confusing.