Mastering Mindbricks
Array Mutation Syntax Guide
Using update dataClause array mutation operators across generated db utility functions.
Array Mutation Syntax Guide
Mindbricks update utilities now support array mutation operators in dataClause.
Supported forms:
arrayField: [ ... ]=> full replacearrayField: { "$add": [ ... ] }=> append valuesarrayField: { "$rem": [ ... ] }=> remove valuesarrayField: { "$addIf": [ ... ] }=> append only missing values- mixed object with any combination of these operators
Operator order
When combined, operators are applied in this order:
$rem$add$addIf
Example:
{
tags: {
$rem: ["legacy"],
$add: ["new"],
$addIf: ["core", "stable"]
}
}
Examples
Replace
await updateOrderById(orderId, {
itemIds: ["a", "b", "c"]
}, this);
Add values
await updateOrderById(orderId, {
itemIds: { $add: ["d", "e"] }
}, this);
Remove values
await updateOrderById(orderId, {
itemIds: { $rem: ["c"] }
}, this);
Add only if missing
await updateOrderById(orderId, {
itemIds: { $addIf: ["a", "x"] }
}, this);
Works in these generated update families
update{Model}ByIdupdate{Model}ByIdListupdate{Model}ByQuery- dbApi update scripts that apply
dataClausebefore persistence
Notes and caveats
- If a field value is a plain array, it is treated as full replacement.
- Mutation operators are resolved against current record data before update.
- For multi-record updates (
ByIdList,ByQuery), operator resolution is per-record. - This gives consistent behavior but is still a read-modify-write flow; for high-contention cases, add DB concurrency controls.
Was this page helpful?
Built with Documentation.AI
Last updated today