h1. Atomic update operations

Before v1.2.6, PlayMorphia user must resort to morphia interface to get atomic update operations done:

bc. Datastore ds = Employee.ds();
UpdateOperations op = ds.createUpdateOperations(Employee.class);
UpdateOperations<Employee> op = ds.createUpdateOperations(Employee.class).inc("salary", 10000).inc("bonus", 99999);
Query<Employee> q = (Query<Employee>)Employee.q().findBy("department", "IT").getMorphiaQuery();
ds.update(q, op);

Now with new v1.2.6, you do it this way:

bc. Employee.o().inc("salary, bonus", 10000, 99999).update("department", "IT");

Start from v1.2.10, one can do update operation on a specific entity model:

bc. Account myAccount = Account.find("username", username);
myAccount._update("email", "superaccount@supercompany.com");

Before v1.2.10, you have to do the following for the same operation:

bc. Account myAccount = Account.find("username", username);
myAccount.email = "superaccount@supercompany.com";
myAccount.save();

Compare with the new <code>_update</code> operation, the old one is much more heavy because it needs to serialize the entire model when saving the updates.

Start from v1.2.12, you can use @_unset@ to set a field to @null@:

bc. myAccount._unset("name,email");

And use @_set@ to set non-null field values:

bc. myAccount._set("name,email", "morphia", "morphia@play.net");

Start from v1.2.12, @_update@ could be used to set mixed null and non-null values:

bc. myAccount._update("name,email", "morphia", null);

However for better performance you want to do it this way:

bc. myAccount.startBatchUpdates()._set("name", "morphia")._unset("email").commit();

h2. <a name="why_atomic">Why atomic update operations</a>

TBD.

h2. <a name="resource">See also</a>

# "Understand morphia model":model
# "Using morphia model":crud
# "Using morphia query":query
# "Morphia doc on updating":http://code.google.com/p/morphia/wiki/Updating
# "Mongo doc on updating":http://www.mongodb.org/display/DOCS/Updating