(Quick Reference)
updateFirst
Purpose
Static method that updates fields of an instance. Only the first instance that matches the query will be updated
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.updateFirst([incomplete: true], {
inc 'actualHours', 5
})
Description
book.updateFirst( id, Closure updateOperations, boolean createIfAbsent = false, WriteConcern wc = null )
book.updateFirst( 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
.