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.

0

1 Answer 1

1

Use $update & $pull:

db.yourCollection.update(
    { },  // <-- your selection criteria
    { $pull: { array: { _id: 2 } }  // <-- what you want to remove from which field
)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.