I have this data set in mongo
{
_id: {
question_id: 3
},
data: {
answer: 11,
count: 114,
result: [
{
_id: 3,
question: "What is your age group?",
options: [
{
id: 10,
option: "<18"
},
{
id: 11,
option: "18-24"
},
{
id: 12,
option: "24-35"
},
{
id: 13,
option: ">35"
}
],
type: "Radio"
}
]
}
},
Here i would like to perform an equals to
check between answer
and result.options.id
and if the value matches it should return result.options.option
So that the desired result is
{
_id: {
question_id: 3
},
data: {
answer:'18-24',
count: 114,
}
},
So far i have tried this
'$project'=>[
'res'=>[
'$map'=>[
'input'=>'$data.result.options',
'as'=>'dt',
'in'=>[
'$cond'=>[
'if'=>[
'$eq'=>[
'$$dt.id',
'$data.answer'
]
],
'then'=>'$$dt.option',
'else'=>'$$dt.id'
]
]
]
]
]
Any clue as to what i am doing wrong . My code always returns the else statement
</div>