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}})
Have you tried the $pull operator ? As in:
db.col.update({_id: 1}, {$pull: {files: 35}})
您可以使用$ pull代替:
db.col.update({ _id : 1 }, {$pull: { files : 35 } })
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.