In MongoDB, you can use the $unset
field update operator to completely remove a field from a document.
The $unset
operator is designed specifically to delete a field and its value from the document.
Database Management Systems
In MongoDB, you can use the $unset
field update operator to completely remove a field from a document.
The $unset
operator is designed specifically to delete a field and its value from the document.
In MongoDB, the $currentDate
operator sets the value of a field to the current date.
It can be set as either a Date or a timestamp type. The default is Date.
$currentDate
is an update operator, and can only be used when updating documents, not when inserting them (although it can be used in upsert operations).
In MongoDB, the $toDate
aggregation operator converts a value to a date
$toDate
takes any valid expression. If the expression can’t be converted to a date, it returns an error. If the expression is null
or missing, it returns null
.
The MongoDB $set
update operator replaces the value of a field with the specified value.
It’s used in conjunction with update operations, for example when using the update()
method to update a document.
MongoDB has a $mul
field update operator that allows you to multiply a value by a specific amount.
If the field doesn’t already exist, it is created and its value is set to zero (0
) using the same numeric type as the multiplier.
MongoDB has an $inc
field update operator that allows you to increment a value by a specific amount.
You can use positive and negative values (i.e. to increment or decrement the value).
If the field doesn’t already exist, it is created with the specified value.
Continue readingThe MongoDB $setOnInsert
field update operator can be used to insert a specific value during an upsert.
If an update operation results in a new document being inserted (i.e. an upsert), then the $setOnInsert
operator takes effect, otherwise it has no effect.
MongoDB has a $max
operator that allows you to update the value of a field only if the specified value is greater than the current value of the field.
In other words, if the $max
value is greater than the current value in the document, the $max
value is used. Otherwise, the document’s value remains unchanged.
MongoDB has a $min
operator that allows you to update the value of a field only if the specified value is less than the current value of the field.
In other words, if the $min
value is less than the current value in the document, the $min
value is used. Otherwise, the document’s value remains unchanged.
In MongoDB, you can use the $pop
operator to remove the first or last element from an array.
Use $pop
in conjunction with a method such as update()
to update the specified document with the change.
Use -1
to remove the first element, and 1
to remove the last.