Spring Data MongoDB - Core

org.springframework.data.mongodb.core.query
Class Update

java.lang.Object
  extended by org.springframework.data.mongodb.core.query.Update
Direct Known Subclasses:
BasicUpdate

public class Update
extends Object

Class to easily construct MongoDB update clauses.

Author:
Thomas Risberg, Mark Pollack, Oliver Gierke, Becca Gaspard, Christoph Strobl, Thomas Darimont

Nested Class Summary
 class Update.AddToSetBuilder
          Builder for creating $addToSet modifier.
static interface Update.Modifier
          Marker interface of nested commands.
static class Update.Modifiers
          Modifiers holds a distinct collection of Update.Modifier
static class Update.Position
           
 class Update.PushOperatorBuilder
          Builder for creating $push modifiers
 
Constructor Summary
Update()
           
 
Method Summary
protected  void addFieldOperation(String operator, String key, Object value)
           
protected  void addMultiFieldOperation(String operator, String key, Object value)
           
 Update.AddToSetBuilder addToSet(String key)
          Update using $addToSet modifier.
 Update addToSet(String key, Object value)
          Update using the $addToSet update modifier
 boolean equals(Object obj)
           
static Update fromDBObject(com.mongodb.DBObject object, String... exclude)
          Creates an Update instance from the given DBObject.
 com.mongodb.DBObject getUpdateObject()
           
 int hashCode()
           
 Update inc(String key, Number inc)
          Update using the $inc update modifier
 boolean modifies(String key)
          Determine if a given key will be touched on execution.
 Update pop(String key, Update.Position pos)
          Update using the $pop update modifier
 Update pull(String key, Object value)
          Update using the $pull update modifier
 Update pullAll(String key, Object[] values)
          Update using the $pullAll update modifier
 Update.PushOperatorBuilder push(String key)
          Update using $push modifier.
 Update push(String key, Object value)
          Update using the $push update modifier
 Update pushAll(String key, Object[] values)
          Update using the $pushAll update modifier.
 Update rename(String oldName, String newName)
          Update using the $rename update modifier
 Update set(String key, Object value)
          Update using the $set update modifier
 Update setOnInsert(String key, Object value)
          Update using the $setOnInsert update modifier
 String toString()
           
 Update unset(String key)
          Update using the $unset update modifier
static Update update(String key, Object value)
          Static factory method to create an Update using the provided key
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Update

public Update()
Method Detail

update

public static Update update(String key,
                            Object value)
Static factory method to create an Update using the provided key

Parameters:
key -
Returns:

fromDBObject

public static Update fromDBObject(com.mongodb.DBObject object,
                                  String... exclude)
Creates an Update instance from the given DBObject. Allows to explicitly exlude fields from making it into the created Update object. Note, that this will set attributes directly and not use $set. This means fields not given in the DBObject will be nulled when executing the update. To create an only-updating Update instance of a DBObject, call set(String, Object) for each value in it.

Parameters:
object - the source DBObject to create the update from.
exclude - the fields to exclude.
Returns:

set

public Update set(String key,
                  Object value)
Update using the $set update modifier

Parameters:
key -
value -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/set/

setOnInsert

public Update setOnInsert(String key,
                          Object value)
Update using the $setOnInsert update modifier

Parameters:
key -
value -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/setOnInsert/

unset

public Update unset(String key)
Update using the $unset update modifier

Parameters:
key -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/unset/

inc

public Update inc(String key,
                  Number inc)
Update using the $inc update modifier

Parameters:
key -
inc -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/inc/

push

public Update push(String key,
                   Object value)
Update using the $push update modifier

Parameters:
key -
value -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/push/

push

public Update.PushOperatorBuilder push(String key)
Update using $push modifier.
Allows creation of $push command for single or multiple (using $each) values.

Parameters:
key -
Returns:
Update.PushOperatorBuilder for given key
See Also:
http://docs.mongodb.org/manual/reference/operator/update/push/, http://docs.mongodb.org/manual/reference/operator/update/each/

pushAll

public Update pushAll(String key,
                      Object[] values)
Update using the $pushAll update modifier.
Note: In mongodb 2.4 the usage of $pushAll has been deprecated in favor of $push $each. push(String)) returns a builder that can be used to populate the $each object.

Parameters:
key -
values -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/pushAll/

addToSet

public Update.AddToSetBuilder addToSet(String key)
Update using $addToSet modifier.
Allows creation of $push command for single or multiple (using $each) values

Parameters:
key -
Returns:
Since:
1.5

addToSet

public Update addToSet(String key,
                       Object value)
Update using the $addToSet update modifier

Parameters:
key -
value -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/addToSet/

pop

public Update pop(String key,
                  Update.Position pos)
Update using the $pop update modifier

Parameters:
key -
pos -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/pop/

pull

public Update pull(String key,
                   Object value)
Update using the $pull update modifier

Parameters:
key -
value -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/pull/

pullAll

public Update pullAll(String key,
                      Object[] values)
Update using the $pullAll update modifier

Parameters:
key -
values -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/pullAll/

rename

public Update rename(String oldName,
                     String newName)
Update using the $rename update modifier

Parameters:
oldName -
newName -
Returns:
See Also:
http://docs.mongodb.org/manual/reference/operator/update/rename/

getUpdateObject

public com.mongodb.DBObject getUpdateObject()

addFieldOperation

protected void addFieldOperation(String operator,
                                 String key,
                                 Object value)

addMultiFieldOperation

protected void addMultiFieldOperation(String operator,
                                      String key,
                                      Object value)

modifies

public boolean modifies(String key)
Determine if a given key will be touched on execution.

Parameters:
key -
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

Spring Data MongoDB - Core

Copyright © 2011-2014–2014 Pivotal Software, Inc.. All rights reserved.