NoBrainer supports atomic operations on document attributes to avoid races
during updates (e.g. incrementing a number).
NoBrainer provides a natural Ruby syntax to describe atomic
operations: assignments ran within a
queue_atomic block are performed
atomically during the next
The following examples use the following base code:
Incrementing a field
Removing items from an array
Adding items to a set
Swapping two fields
Using different fields to compute some value
Removing a field
Using a RQL value
- Atomic operations are performed when invoking
- Multiple atomic operations can be queued.
- Once an attribute has atomic operations queued, validations are no longer performed on that attribute.
- Once an atomic value is queued, the attribute value cannot be read anymore.
The following describes operations that can be performed on various types:
instance.unset(:field)removes the specified field from the document.
instance.field = valueassigns
value, which can be a RQL expression, or some operation using other fields from the same document.
values1 & values2performs the set intersection between
values1 | values2performs the set union of
values1 + values2performs the concatenation of
values1 - values2performs the difference between
values << valueappends
Array, except all operations are done with
value1 + value2performs the concatenation of the two strings.
Integer / Float
+ - / %performs the usual numeric computations.