Navigation
This version of the documentation is archived and no longer supported.

$push

$push

The $push operator appends a specified value to an array. For example:

db.collection.update( { field: value }, { $push: { field: value1 } } );

Here, $push appends value1 to the array identified by value in field. 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.
←   $pullAll $pushAll  →