I'm having a (hopefully) small syntax problem with $pull
in Mongodb.
bulk.find({_id: new mongo.ObjectID(req.session._id)}).updateOne({$pull: {
firstArray: {id: req.params.id},
'secondArray.firstArrayIds': req.params.id
'secondArray.$.firstArrayIds': req.params.id
}});
The firstArray $pull
works just fine.
But the secondArray.firstArrayIds and/or secondArray.$.firstArrayIds
does not. What am I doing wrong here?
This is my data structure:
clients: {
firstArray: [
{
_id: '153'.
someField1: 'someVal1',
}
...
]
secondArray: [
{
_id: '7423'.
someField1: 'someVal1',
firstArrayIds: [153, 154, 155, ...]
}
...
]
}
EDIT What if there are more than one embedded object in secondArray
which firstArrayIds
can contain the id i want to delete. In other words, when deleting an object in firstdArray
i want to delete references in all secondArray
's firstArrayIds
Not just the first match.