# Upsert

*noun*

say it: **“UP-surt”** **/ˈʌpˌsɝt/**

An update that inserts a new document when none matches its filter, and changes the existing one when one does.

## What is **Upsert**?

An **upsert** updates the matching document or inserts a new one if none matches, in one operation.

```javascript
db.stats.updateOne({ userId }, { $inc: { gamesPlayed: 1 } }, { upsert: true })
```

## In a sentence

- “Saving a rating is an **upsert**: the first save creates it, and later saves change it.”
- “With **upsert** set to true, updateOne answered with an upsertedId.”

Level: Journeyman · [More MongoDB terms at this level](https://www.ask-codey.com/glossary?category=mongodb&level=3)

Updated: November 19, 2026

Source: https://www.ask-codey.com/glossary/upsert
