I am trying to add one property if current user has permission or not based on email exists in array of objects.
My input data looks like below.
[
{
nId: 0,
children0: [
{
nId: 3,
access: [
{
permission: "view",
email: "[email protected]"
}
]
},
{
nId: 4,
access: [
{
permission: "view",
email: "[email protected]"
}
]
}
]
}
]
https://mongoplayground.net/p/xZmRGFharAb
[
{
"$addFields": {
"children0": {
"$map": {
"input": "$children0.access",
"as": "accessInfo",
"in": {
"$cond": [
{
"$eq": [
"$$accessInfo.email",
"[email protected]"
]
},
{
"$mergeObjects": [
"$$accessInfo",
{
"hasAccess": true
}
]
},
{
"$mergeObjects": [
"$$accessInfo",
{
"hasAccess": false
}
]
},
]
}
}
}
}
}
]
I also tried this answer as following, but that is also not merging the object.