$pull¶
-
$pull
¶ The
$pull
operator removes all instances of a value from an existing array, as in the following prototype:$pull
removes items from the array in the field namedfield
that match the query in the$pull
statement.If a value (i.e.
<value>
) exists multiple times in an array,$pull
will remove all instances of the value.Example
Given the following document in the
cpuinfo
collection:The following operation will remove the
msr
value from theflags
array:Example
Given the following document in the
profiles
collection:The following operation will remove all occurrences of
7
from thevotes
array.Therefore, the
votes
array would resemble the following:{ votes: [ 3, 5, 6, 8 ] }Conversely, the following operation will remove all items from the array that are larger than
6
:Therefore, the
votes
array would resemble the following: