db.group.insertMany([
{
"name": "a",
"users": [
{
"uname": "A"
},
{
"uname": "B"
},
{
"uname": "C"
}
]
},
{
"name": "b",
"users": [
{
"uname": "A"
},
{
"uname": "D"
},
{
"uname": "E"
}
]
}
]);
Now I want to add a new Field ‘isAPresent’ which checks whether a user with username ‘A’ is present in each group.
db.group.aggregate([
{
$addFields: {
isAPresent: {
$cond:[ {
$eq:['uname','A']
},true,false]
}
}
}
]);
This always giving me false, even though “A” is present in the first and second group