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.
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
Updated