- Reference >
- Operators >
- Update Operators >
- Array Update Operators >
- $slice
$slice¶
-
$slice
¶ New in version 2.4.
The
$slice
modifier limits the number of array elements during a$push
operation. To project, or return, a specified number of array elements from a read operation, see the$slice
projection operator instead.To use the
$slice
modifier, it must appear with the$each
modifier, and the$each
modifier must be the first modifier for the$push
operation.The
<num>
is either a negative number or zero:- If
<num>
is negative, the array<field>
contains only the last<num>
elements. - If
<num>
is zero, the array<field>
is an empty array.
- If