Arrays 取消设置数组元素
是否可以在数组字段上使用$unset运算符并删除与查询匹配的元素。例如,我试图从字段“文件”数组中删除35个 你试过这个吗?例如: 您可以改为使用:Arrays 取消设置数组元素,arrays,mongodb,Arrays,Mongodb,是否可以在数组字段上使用$unset运算符并删除与查询匹配的元素。例如,我试图从字段“文件”数组中删除35个 你试过这个吗?例如: 您可以改为使用: db.col.update({u id:1},{$pull:{files:35}}) { _id : 1, files : [1,12,35,223] } // Ive tried this but it does not work db.col.update({_id : 1}, {$unset : { files : 35}}) //
db.col.update({u id:1},{$pull:{files:35}})
{
_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}})
db.col.update({_id: 1}, {$pull: {files: 35}})