$push¶
-
$push
¶ The
$push
operator appends a specified value to an array. For example:Here,
$push
appendsvalue1
to the array identified byvalue
infield
. Be aware of the following behaviors:- If the field specified in the
$push
statement (e.g.{ $push: { field: value1 } }
) does not exist in the matched document, the operation adds a new array with the specified field and value (e.g.value1
) to the matched document. - The operation will fail if the field specified in the
$push
statement is not an array.$push
does not fail when pushing a value to a non-existent field. - If
value1
is an array itself,$push
appends the whole array as an element in the identified array. To add multiple items to an array, use$pushAll
.
- If the field specified in the