티스토리 뷰

Database/mongoDB

[MongoDB] Update Operators

데브포유 2017. 3. 21. 23:16
반응형

The following modifiers are available for use in update operations; e.g. in db.collection.update() and db.collection.findAndModify().

Specify the operator expression in a document of the form:

{
   <operator1>: { <field1>: <value1>, ... },
   <operator2>: { <field2>: <value2>, ... },
   ...
}

NOTE

For details on specific operator, including syntax and examples, click on the specific operator to go to its reference page.

Update Operators

Fields

NameDescription
$incIncrements the value of the field by the specified amount.
$mulMultiplies the value of the field by the specified amount.
$renameRenames a field.
$setOnInsertSets the value of a field if an update results in an insert of a document. Has no effect on update operations that modify existing documents.
$setSets the value of a field in a document.
$unsetRemoves the specified field from a document.
$minOnly updates the field if the specified value is less than the existing field value.
$maxOnly updates the field if the specified value is greater than the existing field value.
$currentDateSets the value of a field to current date, either as a Date or a Timestamp.

Array

Operators

NameDescription
$Acts as a placeholder to update the first element that matches the query condition in an update.
$addToSetAdds elements to an array only if they do not already exist in the set.
$popRemoves the first or last item of an array.
$pullAllRemoves all matching values from an array.
$pullRemoves all array elements that match a specified query.
$pushAllDeprecated. Adds several items to an array.
$pushAdds an item to an array.

Modifiers

NameDescription
$eachModifies the $push and $addToSet operators to append multiple items for array updates.
$sliceModifies the $push operator to limit the size of updated arrays.
$sortModifies the $push operator to reorder documents stored in an array.
$positionModifies the $push operator to specify the position in the array to add elements.

Bitwise

NameDescription
$bitPerforms bitwise ANDOR, and XOR updates of integer values.

Isolation

NameDescription
$isolatedModifies the behavior of a write operation to increase the isolation of the operation.


반응형