# $dbAddToSet

`$dbAddToSet` adds a value in a list of a document **atomically** (no lost update when several people write at once). The document and the list are created if needed.

## Syntax

```
$dbAddToSet[collection;id;path;value;(maxLength);(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 of the list. Missing counts as an empty list. |
| `value` | The value. Read as JSON when valid (`3`, `"text"`, `{"id":1}`), as text otherwise. |
| `maxLength` | Optional. Keep only the latest `maxLength` items (the oldest are dropped). |
| `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

```bdfd
$dbAddToSet[players;$authorID;items;"sword";100]
```
