- Reference >
- Operators >
- Update Operators >
- Array Update Operators >
- $pop
$pop¶
-
$pop¶ The
$popoperator removes the first or last element of an array. Pass$popa value of1to remove the last element in an array and a value of-1to remove the first element of an array. Consider the following syntax:This operation removes the last item of the array in
fieldin 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
$popbehaviors:- The
$popoperation fails iffieldis not an array. $popwill successfully remove the last item in an array.fieldwill then hold an empty array.
New in version 1.1.
- The