Question

Here is a an example document I have.

Users

{
    "_id": 1,
    "users": [2,3,4,5],
    "scenarios": [11,22,44,55]
}

I'd like remove the elements 2 from users and 11 44 55 from scenarios. I was attemping to perform two $pull in a single update but I can't seem to get it to work with the following.

Users.update(
    { _id: 1},  
    {$pull: { users: 2 }, 
    {scenarios : '11 44 55' }, 
    function(err,numberaffected){}
);

Any help with the following query would be appreciated.

Was it helpful?

Solution

You want to pullAll

Users.update(
    { "_id": 1 },
    { "$pullAll": {"users": [2], "scenarios": [ 11, 44, 55 ]} }
    ,
    function(err, numAffected) {
    }
);

Like that, should do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top