updateOne and $set
noun
say it: “UP-dayt WUN and DOL-er SET” /ˈʌpdeɪt ˈwʌn ənd ˈdɑlər ˈsɛt/
updateOne changes the first MongoDB document that matches a filter; $set sets the given fields and leaves the rest alone.
What does updateOne and $set do?
updateOne changes the first matching document; $set sets fields without touching the rest. updateMany changes all matches.
db.recipes.updateOne({ _id: recipeId }, { $set: { minutes: 15 }, $inc: { views: 1 } })
In a sentence
- “updateOne and $set changed the vendor's stall without touching its products.”
- “Forgetting $set in an update can replace the whole document.”
Level: Apprentice · More MongoDB terms at this level
Updated