- Reference >
- Operators >
- Update Operators >
- Array Update Operators >
- $push
$push¶
-
$push
¶ The
$push
operator appends a specified value to an array.The following example appends
89
to thescores
array for the first document where thename
field equalsjoe
:Note
If the field is absent in the document to update,
$push
adds the array field with the value as its element.If the field is not an array, the operation will fail.
If the value is an array,
$push
appends the whole array as a single element. To add each element of the value separately, use$push
with the$each
modifier.The following example appends each element of
[ 90, 92, 85 ]
to thescores
array for the document where thename
field equalsjoe
:
Changed in version 2.4: You can use the
$push
operator with the following modifiers:When used in conjunction with the other modifiers, the
$each
modifier must be the first modifier.The following example uses: