Update Operators
수정 연산자
- Update Operator는 DB에 저장된 데이터를 수정하거나 새로운 데이터를 추가할 수 있게 하는 연산자이다.
- MongoDB 5.0 버전부터, 수정 연산자는
Document의 Field 이름이 string Type인 경우 Lexicographic Order(사전순)로 처리하고,
numeric Type인 경우 Numeric Order(수치순)로 처리한다.
Example. MongoDB 5.0 vs Earlier
{ $set: { "a.2": <new value>, "a.10": <new value>, } }
MongoDB 5.0 : "a.2" 필드를 먼저 처리한다. (Numeric Order상, 2가 10보다 먼저이기 때문이다.)
MongoDB Earlier : "a.10" 필드를 먼저 처리한다. (Lexicographic Order(상, 1이 2보다 먼저이기 때문이다.)
Fields
Name | Description |
Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
Increments the value of the field by the specified amount.
|
|
Only updates the field if the specified value is less than the existing field value.
|
|
Only updates the field if the specified value is greater than the existing field value.
|
|
Multiplies the value of the field by the specified amount.
|
|
Renames a field.
|
|
Sets the value of a field in a document.
|
|
Sets 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.
|
|
Removes the specified field from a document.
|
Array Operators
Name | Description |
Acts as a placeholder to update the first element that matches the query condition.
|
|
Acts as a placeholder to update all elements in an array for the documents that match the query condition.
|
|
Acts as a placeholder to update all elements that match the arrayFilters condition for the documents that match the query condition.
|
|
Adds elements to an array only if they do not already exist in the set.
|
|
Removes the first or last item of an array.
|
|
Removes all array elements that match a specified query.
|
|
Adds an item to an array.
|
|
Removes all matching values from an array.
|
Array Modifiers
Name | Description |
Modifies the $push operator to specify the position in the array to add elements.
|
|
Modifies the $push operator to limit the size of updated arrays.
|
|
Modifies the $push operator to reorder documents stored in an array.
|
Bitwise
Name | Description |
Performs bitwise AND, OR, and XOR updates of integer values.
|
Reference: MongoDB Documentation (URL)