0

I have the following situation:

{ code: 0, array:[{ _id: 1, ....}, { _id: 2, ....}, { _id: 18, ....}]} 

I need to remove the element inside 'array' field matching the '_id' field.

How can I do that?

Thank you.

1 Answers1

1

Use $update & $pull:

db.yourCollection.update(
    { },  // <-- your selection criteria
    { $pull: { array: { _id: 2 } }  // <-- what you want to remove from which field
)
Akrion
  • 18,117
  • 1
  • 34
  • 54