Thuta Learning
IntermediateData & Databasesintermediate

Update Many Documents

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

To update every document that matches a filter, use the updateMany() method.

javascript
db.inventory.updateMany(
   { qty: { $lt: 50 } },
   {
     $set: { "status": "low" }
   }
)
You should see
(Every document with qty below 50 will get a new field: status: "low")
Update Many Documents | Thuta Learning