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 SummaryModifier and TypeMethodDescriptionstatic <TItem> BsonaddEachToSet(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> BsonCreates 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 BsonbitwiseAnd(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 BsonbitwiseAnd(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 BsonCreates an update that performs a bitwise or between the given integer value and the integral value of the field with the given name.static BsonCreates an update that performs a bitwise or between the given long value and the integral value of the field with the given name.static BsonbitwiseXor(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 BsonbitwiseXor(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 BsonCombine a list of updates into a single update.static BsonCombine a list of updates into a single update.static BsoncurrentDate(String fieldName) Creates an update that sets the value of the field to the current date as a BSON date.static BsoncurrentTimestamp(String fieldName) Creates an update that sets the value of the field to the current date as a BSON timestamp.static BsonCreates an update that increments the value of the field with the given name by the given value.static <TItem> BsonCreates 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> BsonCreates 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 BsonCreates an update that multiplies the value of the field with the given name by the given number.static BsonCreates an update that pops the first element of an array that is the value of the field with the given name.static BsonCreates an update that pops the last element of an array that is the value of the field with the given name.static <TItem> BsonCreates an update that removes all instances of the given value from the array value of the field with the given name.static <TItem> BsonCreates an update that removes all instances of the given values from the array value of the field with the given name.static BsonpullByFilter(Bson filter) Creates an update that removes from an array all elements that match the given filter.static <TItem> BsonCreates an update that adds the given value to the array value of the field with the given name.static <TItem> BsonCreates an update that adds each of the given values to the array value of the field with the given name.static <TItem> BsonpushEach(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 BsonCreates an update that renames a field.static <TItem> BsonCreates an update that sets the value of the field with the given name to the given value.static <TItem> BsonsetOnInsert(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 BsonsetOnInsert(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 BsonCreates an update that deletes the field with the given name.
- 
Method Details- 
combineCombine a list of updates into a single update.- Parameters:
- updates- the list of updates
- Returns:
- a combined update
 
- 
combineCombine a list of updates into a single update.- Parameters:
- updates- the list of updates
- Returns:
- a combined update
 
- 
setCreates 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 name
- value- the value, which may be null
- Returns:
- the update
- MongoDB documentation
- $set
 
- 
unsetCreates an update that deletes the field with the given name.- Parameters:
- fieldName- the non-null field name
- Returns:
- the update
- MongoDB documentation
- $unset
 
- 
setOnInsertCreates 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
 
- 
setOnInsertCreates 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 name
- value- the value, which may be null
- Returns:
- the update
- See Also:
- MongoDB documentation
- $setOnInsert
 
- 
renameCreates an update that renames a field.- Parameters:
- fieldName- the non-null field name
- newFieldName- the non-null new field name
- Returns:
- the update
- MongoDB documentation
- $rename
 
- 
incCreates an update that increments the value of the field with the given name by the given value.- Parameters:
- fieldName- the non-null field name
- number- the value
- Returns:
- the update
- MongoDB documentation
- $inc
 
- 
mulCreates an update that multiplies the value of the field with the given name by the given number.- Parameters:
- fieldName- the non-null field name
- number- the non-null number
- Returns:
- the update
- MongoDB documentation
- $mul
 
- 
minCreates 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 name
- value- the value
- Returns:
- the update
- MongoDB documentation
- $min
 
- 
maxCreates 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 name
- value- the value
- Returns:
- the update
- MongoDB documentation
- $min
 
- 
currentDateCreates 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
 
- 
currentTimestampCreates 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
 
- 
addToSetCreates 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 name
- value- the value, which may be null
- Returns:
- the update
- MongoDB documentation
- $addToSet
 
- 
addEachToSetCreates 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 name
- values- the values
- Returns:
- the update
- MongoDB documentation
- $addToSet
 
- 
pushCreates 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 name
- value- the value, which may be null
- Returns:
- the update
- MongoDB documentation
- $push
 
- 
pushEachCreates 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 name
- values- the values
- Returns:
- the update
- MongoDB documentation
- $push
 
- 
pushEachCreates 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 name
- values- the values
- options- the non-null push options
- Returns:
- the update
- MongoDB documentation
- $push
 
- 
pullCreates 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 name
- value- the value, which may be null
- Returns:
- the update
- MongoDB documentation
- $pull
 
- 
pullByFilterCreates 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
 
- 
pullAllCreates 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 name
- values- the values
- Returns:
- the update
- MongoDB documentation
- $pull
 
- 
popFirstCreates 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
 
- 
popLastCreates 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
 
- 
bitwiseAndCreates 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 name
- value- the value
- Returns:
- the update
 
- 
bitwiseAndCreates 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 name
- value- the value
- Returns:
- the update
- MongoDB documentation
- $bit
 
- 
bitwiseOrCreates 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 name
- value- the value
- Returns:
- the update
- MongoDB documentation
- $bit
 
- 
bitwiseOrCreates 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 name
- value- the value
- Returns:
- the update
- MongoDB documentation
- $bit
 
- 
bitwiseXorCreates 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 name
- value- the value
- Returns:
- the update
 
- 
bitwiseXorCreates 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 name
- value- the value
- Returns:
- the update
 
 
-