I have a mongo database where I need to return populated data but I am not sure how to do it
Here are my collections:
Comment
{
_id: 'someId',
userId: 'someUserId',
answers: {
someQuestionId1: 'this is an answer to the question',
someQuestionId2: 'this is another answer to the question'
}
}
In the answers object each of the keys is an id for a question in a separate collection
Question
{
_id: 'someQuestionId1',
content: {
en-GB: ['someQuestionVersion']
}
}
In the question object the first value in the array is the most recent version of a question
Version
{
_id: 'someQuestionVersion',
content: {
label: 'This is the question label'
}
}
The label inside the version object is the piece of info I need.
I would like the aggregation to return an object that looks like this:
{
_id: 'someId',
userId: 'someUserId',
answers: [{
label: 'This is the question label',
answer: 'this is an answer to the question'
}, {
label: 'This is another question label',
answer: 'this is an another answer to the question'
}
someQuestionId1: 'this is an answer to the question',
someQuestionId2: 'this is another answer to the question'
]
}
Any ideas on how to do this?
question from:
https://stackoverflow.com/questions/65602556/mongo-aggregation-for-id-which-is-set-as-a-key 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…