Class Update
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
Modifier and TypeClassDescriptionclass
Builder for creating$addToSet
modifier.static class
static interface
Marker interface of nested commands.static class
Modifiers holds a distinct collection ofUpdate.Modifier
static enum
class
Builder for creating$push
modifiersNested classes/interfaces inherited from interface org.springframework.data.mongodb.core.query.UpdateDefinition
UpdateDefinition.ArrayFilter
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addMultiFieldOperation
(String operator, String key, Object value) Update using$addToSet
modifier.Update using the $addToSet update modifierThe operator supports bitwiseand
, bitwiseor
, and bitwisexor
operations.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.boolean
filterArray
(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 Update
fromDocument
(org.bson.Document object, String... exclude) Creates anUpdate
instance from the givenDocument
.Get the specification which elements to modify in an array field.org.bson.Document
boolean
int
hashCode()
void
Increment 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 thevalue
if thevalue
is greater than the current value of the field.Update given key to thevalue
if thevalue
is less than the current value of the field.boolean
Determine if a givenkey
will 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$push
modifier.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 Update
Static 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 anUpdate
instance from the givenDocument
. Allows to explicitly exclude fields from making it into the createdUpdate
object. Note, that this will set attributes directly and not use $set. This means fields not given in theDocument
will be nulled when executing the update. To create an only-updatingUpdate
instance of aDocument
, callset(String, Object)
for each value in it.- Parameters:
object
- the sourceDocument
to 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:UpdateDefinition
Increment the value of a given key by1
.- Specified by:
inc
in 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$push
modifier.
Allows creation of$push
command for single or multiple (using$each
) values as well as using$position
.- Parameters:
key
- the field name.- Returns:
Update.PushOperatorBuilder
for given key- See Also:
-
addToSet
Update using$addToSet
modifier.
Allows creation of$push
command 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 thevalue
if thevalue
is 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 thevalue
if thevalue
is 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 bitwisexor
operations.- 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.CriteriaDefinition
is 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.expression
is 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:UpdateDefinition
If true prevents a write operation that affects multiple documents from yielding to other reads or writes once the first document is written.- Specified by:
isIsolated
in interfaceUpdateDefinition
- Returns:
- true if update isolated is set.
-
getUpdateObject
public org.bson.Document getUpdateObject()- Specified by:
getUpdateObject
in interfaceUpdateDefinition
- Returns:
- the actual update in its native
Document
format. Never null.
-
getArrayFilters
Description copied from interface:UpdateDefinition
Get the specification which elements to modify in an array field.UpdateDefinition.ArrayFilter
are passed directly to the driver without further type or field mapping.- Specified by:
getArrayFilters
in interfaceUpdateDefinition
- Returns:
- never null.
-
hasArrayFilters
public boolean hasArrayFilters()- Specified by:
hasArrayFilters
in interfaceUpdateDefinition
- Returns:
- true if
UpdateDefinition
containsarray filters
.
-
addMultiFieldOperation
-
modifies
Determine if a givenkey
will be touched on execution.- Specified by:
modifies
in interfaceUpdateDefinition
- Parameters:
key
- the field name.- Returns:
- true if given field is updated.
-
hashCode
public int hashCode() -
equals
-
toString
-