Grokking MongoDB
0% completed
Upserts, Replacements, and Returning Documents
Not every write fits the pattern of changing named fields in a document that already exists. Sometimes the document may not exist yet, sometimes the program holds a complete new version of it, and sometimes the program needs the changed document back. MongoDB answers these three cases with the upsert option, replaceOne(), and findOneAndUpdate().
The examples continue with the users collection from the Update Operations lesson, and they build on each other, so run them in order. If you are starting fresh, the commands below recreate the three users as that lesson left them.
``
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%