0

I have a collection like this:

_id: {name: 'name', family: 'family'}

i want to remove some objects by _id using by $in, how i can do this? for example my query should be something like:

db.persons.remove({_id: {$in: [ { name: 'name1', family: 'family1' }
                              , { name: 'name2', family: 'family2' }
                              ]
                        }
                 })
1
  • @Neil, you are right.:D actually my problem was the order of fields! if i try db.persons.remove({_id: {$in: [{family: 'family1', name: 'name1'}]}}) nothing happened, but above query is working correctly. Commented Jun 17, 2014 at 7:19

1 Answer 1

1

You can also do this with an $or query and dot notation if your fields are not always in the same order:

db.persons.remove({
    "$or": [
        { "_id.name": "name1", "_id.family": "family1" },
        { "_id.name": "name2", "_id.family": "family2" },
    }
})

Not the mongoose syntax, but you get the idea. It is logically the same thing but the field order is not dependent as it is with the full object you are specifying to $in.

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.