Thuta Learning
IntermediateData & Databasesintermediate

Update Operators

Relax. We'll talk through this in plain words — no textbook voice.

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)