# $dbIncrement

`$dbIncrement` is **atomic**: a hundred people earning XP at the same moment never lose a point, and the guard cannot be raced. When the guard refuses, nothing changes and `$dbLastError` is `conflict`.

## Syntax

```
$dbIncrement[collection;id;path;amount;(min);(max);(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 number. Missing counts as 0. |
| `amount` | The number to add; negative to subtract. Integers stay exact up to 9 007 199 254 740 991. |
| `min` | Optional. The result may not go below it. Use `0` for a balance. |
| `max` | Optional. The result may not go above it. |
| `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 value.
- Empty when refused or failed (see [`$dbLastError`](/docs/dblasterror/)).

## Examples

### Give XP

```bdfd
$dbIncrement[players;$authorID;xp;15]
```

### Spend coins, never below zero

```bdfd
$dbIncrement[wallet;$authorID;cash;-50;0]
```
