Community contributed extensions

Atomic update operations

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

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:

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:

Account myAccount = Account.find("username", username);
myAccount._update("email", "[email protected]");

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

Account myAccount = Account.find("username", username);
myAccount.email = "[email protected]";
myAccount.save();

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

Why atomic update operations

TBD.

See also

  1. Understand morphia model
  2. Using morphia model
  3. Using morphia query
  4. Morphia doc on updating
  5. Mongo doc on updating