- Reference >
- Operators >
- Update Operators >
- Array Update Operators >
- $push
$push¶
-
$push¶ The
$pushoperator appends a specified value to an array.The following example appends
89to thescoresarray for the first document where thenamefield equalsjoe:Note
If the field is absent in the document to update,
$pushadds 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,
$pushappends the whole array as a single element. To add each element of the value separately, use$pushwith the$eachmodifier.The following example appends each element of
[ 90, 92, 85 ]to thescoresarray for the document where thenamefield equalsjoe:
Changed in version 2.4: You can use the
$pushoperator with the following modifiers:When used in conjunction with the other modifiers, the
$eachmodifier must be the first modifier.The following example uses: