Definition
$pullAllThe
$pullAlloperator removes all instances of the specified values from an existing array. Unlike the$pulloperator that removes elements by specifying a query,$pullAllremoves elements that match the listed values.The
$pullAlloperator has the form:{ $pullAll: { <field1>: [ <value1>, <value2> ... ], ... } } To specify a
<field>in an embedded document or in an array, use dot notation.
Behavior
In MongoDB 4.4 and earlier, update operators process document fields in lexicographic order. See Update Operators Behavior for details.
If a <value> to remove is a document or an array,
$pullAll removes only the elements in the array that match
the specified <value> exactly, including order.
Examples
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 ] }