|< < 48 > >|

MongoDB updates

Update

db.inventory.updateOne( { item: "paper" }, { $set: { "size.uom": "cm", status: "P" }, $currentDate: { lastModified: true } } )

  • Find documents satisfying the predicate item = "paper".

  • Apply the specified update. $currentDate sets the lastModified field to the current date.

Delete

db.inventory.deleteMany({ status : "A" })

  • Deletes documents with status = "A".

|< < 48 > >|