Database
dbUpdate
$dbUpdate
$dbUpdate is a merge of one path: the rest of the document is left as it is, and the document is created if it does not exist. For counters, use $dbIncrement instead (a read then a write can lose updates).
Syntax
$dbUpdate[collection;id;path;value;(returnValue)]
Parameters
| Parameter | Description |
|---|---|
collection |
Collection name: lowercase letters, digits, _, . or - (up to 64 characters). It is created on first write. |
id |
Document id, 1 to 128 bytes. Often a Discord ID. |
path |
Dotted path to set, such as stats.wins. The objects on the way are created. |
value |
The new value. Read as JSON when it is valid JSON (5, true, "007", {"a":1}, [1,2]), as text otherwise. A whole number of 16 digits or more (a Discord ID) stays text. Write null to delete the key. |
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.
- The new revision.
- Empty on a handled error.
Examples
$dbUpdate[players;$authorID;title;"Champion"]
$dbUpdate[players;$authorID;stats.wins;12]
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.