Package com.mongodb.client.model
Class Updates
java.lang.Object
com.mongodb.client.model.Updates
A factory for document updates. A convenient way to use this class is to statically import all of its methods, which allows usage like:
collection.updateOne(eq("x", 1), set("x", 2));
- Since:
- 3.1
- MongoDB documentation
- Update Operators
-
Method Summary
Modifier and TypeMethodDescriptionstatic <TItem> Bson
addEachToSet
(String fieldName, List<TItem> values) Creates an update that adds each of the given values to the array value of the field with the given name, unless the value is already present, in which case it does nothingstatic <TItem> Bson
Creates an update that adds the given value to the array value of the field with the given name, unless the value is already present, in which case it does nothingstatic Bson
bitwiseAnd
(String fieldName, int value) Creates an update that performs a bitwise and between the given integer value and the integral value of the field with the given name.static Bson
bitwiseAnd
(String fieldName, long value) Creates an update that performs a bitwise and between the given long value and the integral value of the field with the given name.static Bson
Creates an update that performs a bitwise or between the given integer value and the integral value of the field with the given name.static Bson
Creates an update that performs a bitwise or between the given long value and the integral value of the field with the given name.static Bson
bitwiseXor
(String fieldName, int value) Creates an update that performs a bitwise xor between the given integer value and the integral value of the field with the given name.static Bson
bitwiseXor
(String fieldName, long value) Creates an update that performs a bitwise xor between the given long value and the integral value of the field with the given name.static Bson
Combine a list of updates into a single update.static Bson
Combine a list of updates into a single update.static Bson
currentDate
(String fieldName) Creates an update that sets the value of the field to the current date as a BSON date.static Bson
currentTimestamp
(String fieldName) Creates an update that sets the value of the field to the current date as a BSON timestamp.static Bson
Creates an update that increments the value of the field with the given name by the given value.static <TItem> Bson
Creates an update that sets the value of the field to the given value if the given value is greater than the current value of the field.static <TItem> Bson
Creates an update that sets the value of the field to the given value if the given value is less than the current value of the field.static Bson
Creates an update that multiplies the value of the field with the given name by the given number.static Bson
Creates an update that pops the first element of an array that is the value of the field with the given name.static Bson
Creates an update that pops the last element of an array that is the value of the field with the given name.static <TItem> Bson
Creates an update that removes all instances of the given value from the array value of the field with the given name.static <TItem> Bson
Creates an update that removes all instances of the given values from the array value of the field with the given name.static Bson
pullByFilter
(Bson filter) Creates an update that removes from an array all elements that match the given filter.static <TItem> Bson
Creates an update that adds the given value to the array value of the field with the given name.static <TItem> Bson
Creates an update that adds each of the given values to the array value of the field with the given name.static <TItem> Bson
pushEach
(String fieldName, List<TItem> values, PushOptions options) Creates an update that adds each of the given values to the array value of the field with the given name, applying the given options for positioning the pushed values, and then slicing and/or sorting the array.static Bson
Creates an update that renames a field.static <TItem> Bson
Creates an update that sets the value of the field with the given name to the given value.static <TItem> Bson
setOnInsert
(String fieldName, TItem value) Creates an update that sets the value of the field with the given name to the given value, but only if the update is an upsert that results in an insert of a document.static Bson
setOnInsert
(Bson value) Creates an update that sets the values for the document, but only if the update is an upsert that results in an insert of a document.static Bson
Creates an update that deletes the field with the given name.
-
Method Details
-
combine
Combine a list of updates into a single update.- Parameters:
updates
- the list of updates- Returns:
- a combined update
-
combine
Combine a list of updates into a single update.- Parameters:
updates
- the list of updates- Returns:
- a combined update
-
set
Creates an update that sets the value of the field with the given name to the given value.- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalue
- the value, which may be null- Returns:
- the update
- MongoDB documentation
- $set
-
unset
Creates an update that deletes the field with the given name.- Parameters:
fieldName
- the non-null field name- Returns:
- the update
- MongoDB documentation
- $unset
-
setOnInsert
Creates an update that sets the values for the document, but only if the update is an upsert that results in an insert of a document.- Parameters:
value
- the value- Returns:
- the update
- Since:
- 3.10.0
- See Also:
- MongoDB documentation
- $setOnInsert
-
setOnInsert
Creates an update that sets the value of the field with the given name to the given value, but only if the update is an upsert that results in an insert of a document.- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalue
- the value, which may be null- Returns:
- the update
- See Also:
- MongoDB documentation
- $setOnInsert
-
rename
Creates an update that renames a field.- Parameters:
fieldName
- the non-null field namenewFieldName
- the non-null new field name- Returns:
- the update
- MongoDB documentation
- $rename
-
inc
Creates an update that increments the value of the field with the given name by the given value.- Parameters:
fieldName
- the non-null field namenumber
- the value- Returns:
- the update
- MongoDB documentation
- $inc
-
mul
Creates an update that multiplies the value of the field with the given name by the given number.- Parameters:
fieldName
- the non-null field namenumber
- the non-null number- Returns:
- the update
- MongoDB documentation
- $mul
-
min
Creates an update that sets the value of the field to the given value if the given value is less than the current value of the field.- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalue
- the value- Returns:
- the update
- MongoDB documentation
- $min
-
max
Creates an update that sets the value of the field to the given value if the given value is greater than the current value of the field.- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalue
- the value- Returns:
- the update
- MongoDB documentation
- $min
-
currentDate
Creates an update that sets the value of the field to the current date as a BSON date.- Parameters:
fieldName
- the non-null field name- Returns:
- the update
- MongoDB documentation
- $currentDate
- Date
-
currentTimestamp
Creates an update that sets the value of the field to the current date as a BSON timestamp.- Parameters:
fieldName
- the non-null field name- Returns:
- the update
- MongoDB documentation
- $currentDate
- Timestamp
-
addToSet
Creates an update that adds the given value to the array value of the field with the given name, unless the value is already present, in which case it does nothing- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalue
- the value, which may be null- Returns:
- the update
- MongoDB documentation
- $addToSet
-
addEachToSet
Creates an update that adds each of the given values to the array value of the field with the given name, unless the value is already present, in which case it does nothing- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalues
- the values- Returns:
- the update
- MongoDB documentation
- $addToSet
-
push
Creates an update that adds the given value to the array value of the field with the given name.- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalue
- the value, which may be null- Returns:
- the update
- MongoDB documentation
- $push
-
pushEach
Creates an update that adds each of the given values to the array value of the field with the given name.- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalues
- the values- Returns:
- the update
- MongoDB documentation
- $push
-
pushEach
Creates an update that adds each of the given values to the array value of the field with the given name, applying the given options for positioning the pushed values, and then slicing and/or sorting the array.- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalues
- the valuesoptions
- the non-null push options- Returns:
- the update
- MongoDB documentation
- $push
-
pull
Creates an update that removes all instances of the given value from the array value of the field with the given name.- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalue
- the value, which may be null- Returns:
- the update
- MongoDB documentation
- $pull
-
pullByFilter
Creates an update that removes from an array all elements that match the given filter.- Parameters:
filter
- the query filter- Returns:
- the update
- MongoDB documentation
- $pull
-
pullAll
Creates an update that removes all instances of the given values from the array value of the field with the given name.- Type Parameters:
TItem
- the value type- Parameters:
fieldName
- the non-null field namevalues
- the values- Returns:
- the update
- MongoDB documentation
- $pull
-
popFirst
Creates an update that pops the first element of an array that is the value of the field with the given name.- Parameters:
fieldName
- the non-null field name- Returns:
- the update
- MongoDB documentation
- $pop
-
popLast
Creates an update that pops the last element of an array that is the value of the field with the given name.- Parameters:
fieldName
- the non-null field name- Returns:
- the update
- MongoDB documentation
- $pop
-
bitwiseAnd
Creates an update that performs a bitwise and between the given integer value and the integral value of the field with the given name.- Parameters:
fieldName
- the field namevalue
- the value- Returns:
- the update
-
bitwiseAnd
Creates an update that performs a bitwise and between the given long value and the integral value of the field with the given name.- Parameters:
fieldName
- the field namevalue
- the value- Returns:
- the update
- MongoDB documentation
- $bit
-
bitwiseOr
Creates an update that performs a bitwise or between the given integer value and the integral value of the field with the given name.- Parameters:
fieldName
- the field namevalue
- the value- Returns:
- the update
- MongoDB documentation
- $bit
-
bitwiseOr
Creates an update that performs a bitwise or between the given long value and the integral value of the field with the given name.- Parameters:
fieldName
- the field namevalue
- the value- Returns:
- the update
- MongoDB documentation
- $bit
-
bitwiseXor
Creates an update that performs a bitwise xor between the given integer value and the integral value of the field with the given name.- Parameters:
fieldName
- the field namevalue
- the value- Returns:
- the update
-
bitwiseXor
Creates an update that performs a bitwise xor between the given long value and the integral value of the field with the given name.- Parameters:
fieldName
- the field namevalue
- the value- Returns:
- the update
-