Thuta Learning
IntermediateData & Databasesintermediate

Update One Document

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

To update a single document, use the updateOne() method. The first parameter is the filter, and the second parameter is the change to make, expressed with an update operator.

javascript
db.inventory.updateOne(
   { item: "paper" },
   {
     $set: { "size.uom": "cm" },
     $currentDate: { lastModified: true }
   }
)
You should see
(This will change the size.uom of the document with item "paper" to "cm" and update the lastModified field)