java.lang.Object
org.springframework.data.mongodb.core.query.Update
- All Implemented Interfaces:
UpdateDefinition
- Direct Known Subclasses:
BasicUpdate
Class to easily construct MongoDB update clauses.
- Author:
- Thomas Risberg, Mark Pollack, Oliver Gierke, Becca Gaspard, Christoph Strobl, Thomas Darimont, Alexey Plotnik, Mark Paluch, Pavel Vodrazka
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassBuilder for creating$addToSetmodifier.static classstatic interfaceMarker interface of nested commands.static classModifiers holds a distinct collection ofUpdate.Modifierstatic enumclassBuilder for creating$pushmodifiersNested classes/interfaces inherited from interface org.springframework.data.mongodb.core.query.UpdateDefinition
UpdateDefinition.ArrayFilter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddMultiFieldOperation(String operator, String key, Object value) Update using$addToSetmodifier.Update using the $addToSet update modifierThe operator supports bitwiseand, bitwiseor, and bitwisexoroperations.currentDate(String key) Update given key to current date using $currentDate modifier.currentTimestamp(String key) Update given key to current date using $currentDate : { $type : "timestamp" } modifier.booleanfilterArray(String identifier, Object expression) Filter elements in an array that match the given criteria for update.filterArray(CriteriaDefinition criteria) Filter elements in an array that match the given criteria for update.static UpdatefromDocument(org.bson.Document object, String... exclude) Creates anUpdateinstance from the givenDocument.Get the specification which elements to modify in an array field.org.bson.DocumentbooleaninthashCode()voidIncrement the value of a given key by1.Update using the $inc update modifierIf true prevents a write operation that affects multiple documents from yielding to other reads or writes once the first document is written.isolated()Prevents a write operation that affects multiple documents from yielding to other reads or writes once the first document is written.Update given key to thevalueif thevalueis greater than the current value of the field.Update given key to thevalueif thevalueis less than the current value of the field.booleanDetermine if a givenkeywill be touched on execution.Multiply the value of given key by the given number.pop(String key, Update.Position pos) Update using the $pop update modifierUpdate using the $pull update modifierUpdate using the $pullAll update modifierUpdate using$pushmodifier.Update using the $push update modifierUpdate using the $rename update modifierUpdate using the $set update modifiersetOnInsert(String key, Object value) Update using the $setOnInsert update modifiertoString()Update using the $unset update modifierstatic UpdateStatic factory method to create an Update using the provided key
-
Constructor Details
-
Update
public Update()
-
-
Method Details
-
update
Static factory method to create an Update using the provided key- Parameters:
key- the field to update.- Returns:
- new instance of
Update.
-
fromDocument
Creates anUpdateinstance from the givenDocument. Allows to explicitly exclude fields from making it into the createdUpdateobject. Note, that this will set attributes directly and not use $set. This means fields not given in theDocumentwill be nulled when executing the update. To create an only-updatingUpdateinstance of aDocument, callset(String, Object)for each value in it.- Parameters:
object- the sourceDocumentto create the update from.exclude- the fields to exclude.- Returns:
- new instance of
Update.
-
set
Update using the $set update modifier- Parameters:
key- the field name.value- can be null. In this case the property remains in the db with a null value. To remove it useunset(String).- Returns:
- this.
- See Also:
-
setOnInsert
Update using the $setOnInsert update modifier- Parameters:
key- the field name.value- can be null.- Returns:
- this.
- See Also:
-
unset
Update using the $unset update modifier- Parameters:
key- the field name.- Returns:
- this.
- See Also:
-
inc
Update using the $inc update modifier- Parameters:
key- the field name.inc- must not be null.- Returns:
- this.
- See Also:
-
inc
Description copied from interface:UpdateDefinitionIncrement the value of a given key by1.- Specified by:
incin interfaceUpdateDefinition- Parameters:
key- must not be null.
-
push
Update using the $push update modifier- Parameters:
key- the field name.value- can be null.- Returns:
- this.
- See Also:
-
push
Update using$pushmodifier.
Allows creation of$pushcommand for single or multiple (using$each) values as well as using$position.- Parameters:
key- the field name.- Returns:
Update.PushOperatorBuilderfor given key- See Also:
-
addToSet
Update using$addToSetmodifier.
Allows creation of$pushcommand for single or multiple (using$each) values- Parameters:
key- the field name.- Returns:
- new instance of
Update.AddToSetBuilder. - Since:
- 1.5
-
addToSet
Update using the $addToSet update modifier- Parameters:
key- the field name.value- can be null.- Returns:
- this.
- See Also:
-
pop
Update using the $pop update modifier- Parameters:
key- the field name.pos- must not be null.- Returns:
- this.
- See Also:
-
pull
Update using the $pull update modifier- Parameters:
key- the field name.value- can be null.- Returns:
- this.
- See Also:
-
pullAll
Update using the $pullAll update modifier- Parameters:
key- the field name.values- must not be null.- Returns:
- this.
- See Also:
-
rename
Update using the $rename update modifier- Parameters:
oldName- must not be null.newName- must not be null.- Returns:
- this.
- See Also:
-
currentDate
Update given key to current date using $currentDate modifier.- Parameters:
key- the field name.- Returns:
- this.
- Since:
- 1.6
- See Also:
-
currentTimestamp
Update given key to current date using $currentDate : { $type : "timestamp" } modifier.- Parameters:
key- the field name.- Returns:
- this.
- Since:
- 1.6
- See Also:
-
multiply
Multiply the value of given key by the given number.- Parameters:
key- must not be null.multiplier- must not be null.- Returns:
- this.
- Since:
- 1.7
- See Also:
-
max
Update given key to thevalueif thevalueis greater than the current value of the field.- Parameters:
key- must not be null.value- must not be null.- Returns:
- this.
- Since:
- 1.10
- See Also:
-
min
Update given key to thevalueif thevalueis less than the current value of the field.- Parameters:
key- must not be null.value- must not be null.- Returns:
- this.
- Since:
- 1.10
- See Also:
-
bitwise
The operator supports bitwiseand, bitwiseor, and bitwisexoroperations.- Parameters:
key- the field name.- Returns:
- this.
- Since:
- 1.7
-
isolated
Prevents a write operation that affects multiple documents from yielding to other reads or writes once the first document is written.
Use withMongoOperations.updateMulti(Query, UpdateDefinition, Class).- Returns:
- this.
- Since:
- 2.0
-
filterArray
Filter elements in an array that match the given criteria for update.CriteriaDefinitionis passed directly to the driver without further type or field mapping.- Parameters:
criteria- must not be null.- Returns:
- this.
- Since:
- 2.2
-
filterArray
Filter elements in an array that match the given criteria for update.expressionis used directly with the driver without further type or field mapping.- Parameters:
identifier- the positional operator identifier filter criteria name.expression- the positional operator filter expression.- Returns:
- this.
- Since:
- 2.2
-
isIsolated
Description copied from interface:UpdateDefinitionIf true prevents a write operation that affects multiple documents from yielding to other reads or writes once the first document is written.- Specified by:
isIsolatedin interfaceUpdateDefinition- Returns:
- true if update isolated is set.
-
getUpdateObject
public org.bson.Document getUpdateObject()- Specified by:
getUpdateObjectin interfaceUpdateDefinition- Returns:
- the actual update in its native
Documentformat. Never null.
-
getArrayFilters
Description copied from interface:UpdateDefinitionGet the specification which elements to modify in an array field.UpdateDefinition.ArrayFilterare passed directly to the driver without further type or field mapping.- Specified by:
getArrayFiltersin interfaceUpdateDefinition- Returns:
- never null.
-
hasArrayFilters
public boolean hasArrayFilters()- Specified by:
hasArrayFiltersin interfaceUpdateDefinition- Returns:
- true if
UpdateDefinitioncontainsarray filters.
-
addMultiFieldOperation
-
modifies
Determine if a givenkeywill be touched on execution.- Specified by:
modifiesin interfaceUpdateDefinition- Parameters:
key- the field name.- Returns:
- true if given field is updated.
-
hashCode
public int hashCode() -
equals
-
toString
-