OPTIONS
翻译或纠错本页面

$pullAll

$pullAll

The $pullAll operator removes all instances of the specified values from an existing array.

db.collection.update( <query>,
                      { $pullAll: { <arrayField>: [ <value1>, <value2> ... ] } }
                    )

Unlike the $pull operator that removes elements by specifying a query, $pullAll removes elements that match the listed values.

For example, given the following document in the survey collection:

{ _id: 1, scores: [ 0, 2, 5, 5, 1, 0 ] }

The following operation removes all instances of the value 0 and 5 from the scores array:

db.survey.update( { _id: 1 }, { $pullAll: { scores: [ 0, 5 ] } } )

After the operation, the updated document has all instances of 0 and 5 removed from the scores field:

{ "_id" : 1, "scores" : [  2,  1 ] }
←   $pop $pull  →
ON THIS PAGE