MongoDB update operators (https://docs.mongodb.com/manual/reference/operator/update/#update-operators) are needed in order to effect changes when performing an update. Update operators are categorized according to what element they affect: fields, arrays, modifiers, and bitwise.Â
The following table summarizes the more important update operators:
Affects ... | Operator | Description |
Fields | $rename | Allows you to rename a field |
$set | Overwrites the current value of the field with the new, updated, value | |
$unset | Deletes the current value of a field | |
Arrays | $ | Placeholder for first element that matches the filter query criteria |
$[] | Placeholder for all elements that match the filter query criteria | |
$addToSet | Adds an element to the array only if it doesn't already exist | |
$push | Adds an item to the array | |
Modifiers | $each | Works with $push to append multiple items to the array |
$sort | Works with $push to re-order the array | |
Bitwise | $bit | Used to... |