Database
dbBatch
$dbBatch
$dbBatch is the transaction of the database: all the operations apply, or none does. There is no open transaction in a script; the batch is the unit. At most 20 operations, all in the same space.
Syntax
$dbBatch[operations;(returnValue)]
Parameters
| Parameter | Description |
|---|---|
operations |
A JSON list of operations, each {"op":..., "collection":..., "id":...} with value, path, delta, min, max, max_len, rev or to_id as needed. op is one of set, create, merge, incr, push, pull, addToSet, delete, transfer. |
returnValue |
Optional - yes to return the result, no to return nothing. Absent: a call written on its own prints nothing, a call used as a value ($var[r;$dbSet[...]]) returns it. Any other value raises an error. |
Return value
Used on its own in a script, the function prints nothing, so no revision or JSON leaks into the message. Used as a value of another function, or with returnValue set to yes, it returns the result below.
- A JSON list with one result per operation (
{"doc":...}or{"deleted":...}). - Empty when the batch was refused (nothing was written).
Examples
$dbBatch[[{"op":"incr","collection":"wallet","id":"$authorID","path":"cash","delta":-50,"min":0},{"op":"push","collection":"players","id":"$authorID","path":"items","value":"potion"}]]
Try it
Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.