Reputation: 301
Actually am trying to update an array in my document which have read property is set to false here what i have done so far.
const user = await User.update(
{
_id: req.userData.id
},
{
$set: {
"notifications.$[elem].read": true
},
arrayFilters: [
{
"elem.read": false
}
], multi : true
}
);
but am getting an error
(node:12572) UnhandledPromiseRejectionWarning: MongoError: No array filter found for identifier 'elem' in path 'notifications.$[elem].read'
Upvotes: 0
Views: 28
Reputation: 13103
arrayFilters should be defined in options
.
Try below code:
const user = await User.update(
{
_id: req.userData.id
},
{
$set: {
"notifications.$[elem].read": true
}
},
{
arrayFilters: [
{
"elem.read": false
}
],
multi : true
}
);
Upvotes: 1