Update Operators#

The following modifiers are available for use in update operations, for example, in petdb.PetCollection.update() and petdb.PetCollection.update_one().

Warning

Any update operator doesn’t support nesting object query, you should only use the dot notation to specify fields.

{"$set": {"info.name": "Item 1"}} # Good
{"$set": {"info": {"name": "Item 1"}}} # Wrong

Fields#

$set

Sets the value of a field in a document.

$unset

Removes the specified field from a document.

$inc

Increments the value of the field by the specified amount.

$map

Calculates and sets the value of a field depending on its current value.

Arrays#

$push, $append

Adds an item to an array.

$addToSet

Adds elements to an array only if they do not already exist in the set.

$pull, $remove

Removes all array elements that match a specified query.