Thuta Learning
MongoDB
IntermediateData & DatabasesIntermediate

Update One Document

MongoDBLesson 11

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)

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.

Update One Document | Thuta Learning