0

Is it possible to use the $unset operator on array field and remove an element that matches a query. For example i'm trying to remove 35 from field "files" array.

{
  _id : 1,
  files : [1,12,35,223]
}
// Ive tried this but it does not work
db.col.update({_id : 1}, {$unset : { files : 35}})
// or this does not work
db.col.update({_id : 1}, {$unset : { "files.35" : 1}})

2 Answers 2

2

Have you tried the $pull operator? As in:

db.col.update({_id: 1}, {$pull: {files: 35}})
Sign up to request clarification or add additional context in comments.

Comments

0

You can use $pull instead:

db.col.update({ _id : 1 }, {$pull: { files : 35 } })

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.