Thuta Learning
MongoDB
IntermediateData & Databasesintermediate

Update One Document

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)
Update One Document | Thuta Learning