MongoDB | Update Operators

Fields

NameDescription
$currentDateSets the value of a field to current date, either as a Date or a Timestamp.
$incIncrements the value of the field by the specified amount.
$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.
$mulMultiplies the value of the field by the specified amount.
$renameRenames a field.
$setSets the value of a field in a document.
$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.
$unsetRemoves the specified field from a document.

Array

Operators

NameDescription
$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.
$[<identifier>]Acts as a placeholder to update all elements that match the arrayFilters condition for the documents that match the query condition.
$addToSetAdds elements to an array only if they do not already exist in the set.
$popRemoves the first or last item of an array.
$pullRemoves all array elements that match a specified query.
$pushAdds an item to an array.
$pullAllRemoves all matching values from an array.

Modifiers

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

Bitwise

NameDescription
$bitPerforms bitwise AND, OR, and XOR updates of integer values.
Last updated on Sep 28, 2021 03:21 UTC
Built with Hugo
Theme Stack designed by Jimmy