Package dev.morphia.query.updates
Class UpdateOperators
java.lang.Object
dev.morphia.query.updates.UpdateOperators
Defines helper methods for specifying operations for updates or findAndModify
-
Method Summary
Modifier and TypeMethodDescriptionstatic UpdateOperator
The $addToSet operator adds a value to an array unless the value is already present, in which case $addToSet does nothing to that array.static UpdateOperator
The $addToSet operator adds a value to an array unless the value is already present, in which case $addToSet does nothing to that array.static UpdateOperator
The $bit operator performs a bitwise update of a field.static UpdateOperator
Multiplies the value of the field by the specified amount.static CurrentDateOperator
currentDate
(String field) The $currentDate operator sets the value of a field to the current date, either as a Date or a timestamp.static UpdateOperator
Decrements the value of the field by one.static UpdateOperator
Decrements the value of the field by the specified amount.static UpdateOperator
Increments the value of the field by one.static UpdateOperator
Increments the value of the field by the specified amount.static UpdateOperator
Only updates the field if the specified value is greater than the existing field value.static UpdateOperator
Only updates the field if the specified value is greater than the existing field value.static UpdateOperator
Only updates the field if the specified value is greater than the existing field value.static UpdateOperator
Only updates the field if the specified value is less than the existing field value.static UpdateOperator
Only updates the field if the specified value is less than the existing field value.static UpdateOperator
Only updates the field if the specified value is less than the existing field value.static UpdateOperator
Multiplies the value of the field by the specified amount.static UpdateOperator
The $bit operator performs a bitwise update of a field.static PopOperator
The $pop operator removes the first or last element of an array.static UpdateOperator
The $pull operator removes from an existing array all instances of a value or values that match a specified condition.static UpdateOperator
The $pull operator removes from an existing array all instances of a value or values that match a specified condition.static UpdateOperator
The $pullAll operator removes all instances of the specified values from an existing array.static PushOperator
The $push operator appends a specified value to an array.static PushOperator
The $push operator appends a specified value to an array.static UpdateOperator
Renames a field.static UpdateOperator
The $set operator replaces the value of a field with the specified value.static UpdateOperator
The $set operator replaces the value of a field with the specified value.static UpdateOperator
setOnInsert
(Map<String, Object> values) If an update operation with upsert: true results in an insert of a document, then $setOnInsert assigns the specified values to the fields in the document.static UpdateOperator
The $unset operator deletes a particular field.static UpdateOperator
The $bit operator performs a bitwise update of a field.
-
Method Details
-
addToSet
The $addToSet operator adds a value to an array unless the value is already present, in which case $addToSet does nothing to that array.- Parameters:
field
- the field to updatedvalue
- the value to add- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $addToSet
-
addToSet
The $addToSet operator adds a value to an array unless the value is already present, in which case $addToSet does nothing to that array. By default, this operator will use $each to add each element in the given list to the stored array in the document.- Parameters:
field
- the field to updatedvalues
- the values to add- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $addToSet
- Update Operator: $each
-
and
The $bit operator performs a bitwise update of a field. The operator supports bitwise and, bitwise or, and bitwise xor (i.e. exclusive or) operations.- Parameters:
field
- the field to updatevalue
- the value to use for the update- Returns:
- the update operator
- See Also:
- MongoDB documentation
- Update Operator: $bit
-
bit
Multiplies the value of the field by the specified amount.- Parameters:
field
- the field to multiplyvalue
- the number to multiply by- Returns:
- the update operator
- Since:
- 3.0
- Since server release
- 5.0
- MongoDB documentation
- Update Operator: $bit
-
currentDate
The $currentDate operator sets the value of a field to the current date, either as a Date or a timestamp. The default type is Date.- Parameters:
field
- the field to set- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $currentDate
-
dec
Decrements the value of the field by one.- Parameters:
field
- the field to decrement- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $dec
-
dec
Decrements the value of the field by the specified amount.- Parameters:
field
- the field to decrementvalue
- the number to decrement by- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $dec
-
inc
Increments the value of the field by the specified amount.- Parameters:
field
- the field to incrementvalue
- the number to increment by- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $inc
-
inc
Increments the value of the field by one.- Parameters:
field
- the field to increment- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $inc
-
max
Only updates the field if the specified value is greater than the existing field value.- Parameters:
field
- the field to updatevalue
- the max value to apply- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $max
-
max
Only updates the field if the specified value is greater than the existing field value.- Parameters:
field
- the field to updatevalue
- the max value to apply- Returns:
- the update operator
- Since:
- 2.2
- MongoDB documentation
- Update Operator: $max
-
max
Only updates the field if the specified value is greater than the existing field value.- Parameters:
field
- the field to updatevalue
- the max value to apply- Returns:
- the update operator
- Since:
- 2.2
- MongoDB documentation
- Update Operator: $max
-
min
Only updates the field if the specified value is less than the existing field value.- Parameters:
field
- the field to updatevalue
- the min value to apply- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $min
-
min
Only updates the field if the specified value is less than the existing field value.- Parameters:
field
- the field to updatevalue
- the min value to apply- Returns:
- the update operator
- Since:
- 2.2
- MongoDB documentation
- Update Operator: $min
-
min
Only updates the field if the specified value is less than the existing field value.- Parameters:
field
- the field to updatevalue
- the min value to apply- Returns:
- the update operator
- Since:
- 2.2
- MongoDB documentation
- Update Operator: $min
-
mul
Multiplies the value of the field by the specified amount.- Parameters:
field
- the field to multiplyvalue
- the number to multiply by- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $mul
-
or
The $bit operator performs a bitwise update of a field. The operator supports bitwise and, bitwise or, and bitwise xor (i.e. exclusive or) operations.- Parameters:
field
- the field to updatevalue
- the value to use for the update- Returns:
- the update operator
- See Also:
- MongoDB documentation
- Update Operator: $bit
-
pop
The $pop operator removes the first or last element of an array. This operation can remove the first of the last value but defaults to removing the last.- Parameters:
field
- the field to update- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $pop
-
pull
The $pull operator removes from an existing array all instances of a value or values that match a specified condition.- Parameters:
field
- the field to updatefilters
- the filters to apply- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $pull
-
pull
The $pull operator removes from an existing array all instances of a value or values that match a specified condition.- Parameters:
field
- the field to updatevalue
- the value to pull- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $pull
-
pullAll
The $pullAll operator removes all instances of the specified values from an existing array. Unlike the $pull operator that removes elements by specifying a query, $pullAll removes elements that match the listed values.- Parameters:
field
- the field to updatevalues
- the values to remove- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $pullAll
-
push
The $push operator appends a specified value to an array.- Parameters:
field
- the field to updatevalue
- the value to add- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $push
-
push
The $push operator appends a specified value to an array.- Parameters:
field
- the field to updatevalues
- the values to add- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $each
- Update Operator: $push
-
rename
Renames a field.- Parameters:
field
- the field to renamevalue
- the new name- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $rename
-
set
The $set operator replaces the value of a field with the specified value.- Parameters:
field
- the field to setvalue
- the value to set- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $set
-
set
The $set operator replaces the value of a field with the specified value.- Parameters:
value
- the value to set- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $set
-
setOnInsert
If an update operation with upsert: true results in an insert of a document, then $setOnInsert assigns the specified values to the fields in the document. If the update operation does not result in an insert, $setOnInsert does nothing.- Parameters:
values
- the fields and their values to insert- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $setOnInsert
-
unset
The $unset operator deletes a particular field.- Parameters:
field
- the field to set- Returns:
- the update operator
- MongoDB documentation
- Update Operator: $unset
-
xor
The $bit operator performs a bitwise update of a field. The operator supports bitwise and, bitwise or, and bitwise xor (i.e. exclusive or) operations.- Parameters:
field
- the field to updatevalue
- the value to use for the update- Returns:
- the update operator
- See Also:
- MongoDB documentation
- Update Operator: $bit
-