I'm trying to execute a query which remove some specific elements which match at least one condition from a set of conditions,
{
id: 'myId',
path2: [{
a: '1'
},{
a: '2'
},{
a: '3'
}]
}
and update it to:
{
id: 'myId',
path2: [{
a: '1'
}]
}
Here, I removed from path2
all elements where the value of the 'a' field is equal to either 2 or 3.
I tried the following with no success (I'm using mongoose):
let conditions = ['2', '3'];
myModel.findOneAndUpdate({id: 'myId'},
{$pull: {path2: {$elemMatch: {a: {$in: conditions}}}}}
);
Thank you in advance.