0

a doc:

{"_id":1,"m":[{"id":1,"m":11},{"id":2,"m":22},{"id":3,"m":33}]}

I want remove "m.id" == 1 AND "m.id" == 2 in single update. I can use $in, like:

update({"_id":1},{$pull:{"m":{$in:[{"id":1,"m":11},{"id":2,"m":22}]}}})

But it requires the whole doc rather than "m.id" $in [1,2]

1 Answer 1

2

If you want to only specify the id property from the m array objects, you can run the following query:

db.test.update({_id: 1}, {
    $pull: {
        m: {
            id: {
                $in: [1,2]
            }
        }
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.