$pop¶
-
$pop
¶ The
$pop
operator removes the first or last element of an array. Pass$pop
a value of1
to remove the last element in an array and a value of-1
to remove the first element of an array. Consider the following syntax:This operation removes the last item of the array in
field
in the document that matches the query statement{ field: value }
. The following example removes the first item of the same array:Be aware of the following
$pop
behaviors:- The
$pop
operation fails iffield
is not an array. $pop
will successfully remove the last item in an array.field
will then hold an empty array.
New in version 1.1.
- The