Thuta Learning
MongoDB
IntermediateData & DatabasesIntermediate

Update Operators

MongoDBLesson 13

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)

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.