# Add or change a row

> Change the row that matches, or add it if there's none.

Source: https://docs.buildcord.dev/nodes/variables-and-data/add-or-change-row/

`data.upsert` does in one step what would otherwise take [Find rows](https://docs.buildcord.dev/nodes/variables-and-data/find-rows), a branch, and [Add row](https://docs.buildcord.dev/nodes/variables-and-data/add-row) or [Change rows](https://docs.buildcord.dev/nodes/variables-and-data/change-rows).

## Settings

| Setting | What it does |
| --- | --- |
| Collection | Which collection. |
| Where | Which row, such as `user = {user.id}`. A new row starts with these `column = value` parts. |
| Set | Columns to replace, one `column: value` per line. |
| Add to | Number columns to add to, one `column: equation` per line, such as `xp: 10`. A new row starts them from 0. |

## Ways out

`out`. Turn on **If it fails** for a red way out.

## Produces

| Token | Value |
| --- | --- |
| `{upserted.id}` | The number of the row changed or added |
| `{upserted.created}` | `true` if it was added, `false` if it was there already |

## Notes

- Runs doing this for the same row take turns, so two messages from a new member at once make one row, not two.
- Every matching row is changed; make the **Where** pick one.

## Example

A levels bot, on **Message sent**: add or change the row where `user = {user.id}`, adding `xp: 5`.

## Related

- [Change rows](https://docs.buildcord.dev/nodes/variables-and-data/change-rows)
- [One run at a time](https://docs.buildcord.dev/nodes/variables-and-data/one-run-at-a-time)
