Update Operators
noun
say it: “UP-dayt AH-puh-ray-terz” /ˈʌpˌdeɪt ˈɑpəˌreɪtərz/
Special MongoDB instructions, such as $set and $inc, that change certain fields of a document without replacing the rest.
What are update operators in MongoDB?
Update operators are $-prefixed instructions that change parts of a document in place: $set sets fields, $inc adds to a number, $push adds to an array and $pull removes from one. Without them, an update would replace the whole document.
await vendors.updateOne(
{ name: "Bee Happy Honey" },
{ $set: { stall: 12 }, $inc: { rating: 0.1 }, $push: { products: "beeswax" } },
);
In a sentence
- “With update operators, one updateOne call moved the vendor to stall 12 and added beeswax to its products.”
- “Update operators such as $inc change a number in the database itself, so two updates at once don't lose a count.”
Level: Apprentice · More MongoDB terms at this level
Updated