Upserts and Replacing a Whole Document

An upsert updates a document when the filter finds one and inserts it when it doesn't, $setOnInsert sets values only on that first insert, replaceOne swaps in a whole new version, and findOneAndUpdate changes a document and hands it back.

By

Updated

Cheat sheet: Upserts and Replacing a Whole Document
Category
MongoDB
Level
Journeyman
Tags
$setOnInsert, findOneAndUpdate, mongodb, replaceOne, Upsert