Update API
Math operators, field operators and array operators.
Field operators
$set
$set{
$set: {
<fieldName1>: <value1>,
<fieldName2>: <value2>,
...etc
}
}/**
* Update a document where age is 1
* to age 5 and name: "alex"
*/
db.update({
filter: {age: 1},
update: {
$set: {
age: 5,
name: "alex"
}
}
});$unset
$unset{
$unset: {
<fieldName1>: "",
<fieldName2>: "",
...etc
}
}/**
* Sets the "lastLogin" field to undefiend
* for documents where age is 1
*/
db.update({
filter: {age: 1},
update: {
$unset: {
lastLogin: ""
}
}
});$setOnInsert
$setOnInsert$rename
$rename$currentDate
$currentDateMathematical operators
$inc
$inc$mul
$mul$min
$min$max
$maxArray operators
$addToSet
$addToSet$pop
$pop$pull
$pull$pullAll
$pullAll$push
$pushArray push modifiers
$each
$each$slice
$slice$position
$position$sort
$sortLast updated