(Quick Reference)

update

Purpose

Updates fields of instances

Be aware that after calling update the domain class instance is not refreshed automatically. You need to fetch the entity from db again to get the new state.

Examples

// increase field value of actualHours by 5
task.update {
  inc 'actualHours', 5
}

// increase field value of actualHours by 5, create entity if not in db Task.update(params.id, { inc 'actualHours', 5 }, true)

// update set document.update { add 'tags', 'mongodb' // add string 'mongodb' to the 'tags' set }

Description

On instances:

book.update( Closure updateOperations, boolean createIfAbsent = false, WriteConcern wc = null )

The static method updates all matched instances:

book.update( id, Closure updateOperations, boolean createIfAbsent = false, WriteConcern wc = null )
book.update( Map query, Closure updateOperations, boolean createIfAbsent = false, WriteConcern wc = null )

Parameters:

  • id - id of the entity
  • query - query as used in findAll method
  • updateOperations - This closure is executed within the context of morphias UpdateOperations
  • createIfAbsent - If set to true, flieds that are not present in entity will be created
  • wc - A WriteConcern object which configures the write strategy for the update operation

See also

.