I am trying to update the notifications
property from false
to true
by using MongoDb's arrayFilters
.
This is what the array/object looks like
This is what I have tried:
'$set':
{
"userObject.$.notificationsArray.$[element].notifications" : true
},
}), { arrayFilters: [{"element": 'e8b7589f-cc72-4fb3-a38b-855ae1106ab2'}] }
but I keep getting this error: No array filter found for identifier 'element' in path 'userObject.$.notificationsArray.$[element].notifications'
What am I doing wrong?
CodePudding user response:
The entire document model isn't shown in the question, but perhaps this is enough to show how to use "arrayFilters"
for the task.
db.collection.update({
"_id": 0
},
{
"$set": {
"userObject.notificationsArray.$[current].notifications": true
}
},
{
"arrayFilters": [
{
"current.chatroom": "e8b7589f-cc72-4fb3-a38b-855ae1106ab2"
}
]
})
Try it on mongoplayground.net.