Mongoose deleting (pull) a document within an array, does not work with ObjectID

It seems that the above code would not work. It should not even have worked for the first example I gave.

In the end I was supported by this answer here: MongoDB, remove object from array

Here is my working code:

userAccounts.update( 
    { userId: usr.userId },
    {
        $pull: {
            connections: { _id : connId }
        }
    },
    { safe: true },
    function removeConnectionsCB(err, obj) {
        // ...
    }
);

Leave a Comment