$push¶
-
$push¶ The
$pushoperator appends a specified value to an array. For example:Here,
$pushappendsvalue1to the array identified byvalueinfield. Be aware of the following behaviors:- If the field specified in the
$pushstatement (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
$pushstatement is not an array.$pushdoes not fail when pushing a value to a non-existent field. - If
value1is an array itself,$pushappends 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