Thuta Learning
MongoDB
IntermediateData & Databasesintermediate

Update Operators

Common operators used for updates:

• $set: sets a field's value, or adds it if it doesn't exist

• $inc: increases or decreases a number field's value

• $unset: removes a field

• $push: adds a new item into an array field

javascript
// Increment the quantity of "journal" by 5
db.inventory.updateOne(
   { item: "journal" },
   { $inc: { qty: 5 } }
)
You should see
(The qty for "journal" will go from 25 up to 30)
Update Operators | Thuta Learning