Delete object from array by given _id in in Mongoose Delete object from array by given _id in in Mongoose mongodb mongodb

Delete object from array by given _id in in Mongoose


Quote from SERVER-2016:

The argument to $pull is already applied to each element of the target array, so using $elemMatch is redundant in the update context.

So just execute your query without $elemMatch:

User    .findByIdAndUpdate(req.user._id, {        $pull: {events: {            _id: _eventId   //_eventId is string representation of event ID        }}    }, function(err) {        // ...    });