Reputation: 1726
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}})
Upvotes: 0
Views: 114
Reputation: 1288
You can use $pull instead:
db.col.update({ _id : 1 }, {$pull: { files : 35 } })
Upvotes: 0
Reputation: 6203
Have you tried the $pull operator? As in:
db.col.update({_id: 1}, {$pull: {files: 35}})
Upvotes: 2