The data are as follows:
Db.inventory.insertMany ([{item:"Canvas", Qty: -, size: {h: -W:35.5, UoM:"cm"}, Status:"A"}, {item:"Journal", Qty: -, size: {h: -W: +, UoM:"cm"}, Status:"A"}, {item:"Mat", Qty: -, size: {h:27.9W:35.5, UoM:"cm"}, Status:"A"}, {item:"mousepad", Qty: -, size: {h: +W:22.85, UoM:"cm"}, Status:"P"}, {item:"Notebook", Qty: -, size: {h:8.5W: One, UoM:"inch"}, Status:"P"}, {item:"Paper", Qty: -, size: {h:8.5W: One, UoM:"inch"}, Status:"D"}, {item:"Planner", Qty: the, size: {h:22.85W: -, UoM:"cm"}, Status:"D"}, {item:"postcard", Qty: $, size: {h:TenW:15.25, UoM:"cm"}, Status:"A"}, {item:"Sketchbook", Qty: the, size: {h: -W: +, UoM:"cm"}, Status:"A"}, {item:"Sketch Pad", Qty: the, size: {h:22.85W:30.5, UoM:"cm"}, Status:"A" }]);
First, the shell executes the UPDATE statement
# Update a document
Db.inventory.updateOne ({item:"Paper" }, { $Set: {"Size.uom":"cm", Status:"P"}, $currentDate: {lastmodified:true } })
# Update multiple documentdb.inventory.updateMany ({"Qty": {$lt: - } }, { $Set: {"Size.uom":"inch", Status:"P"}, $currentDate: {lastmodified:true } })
# Replace a documentdb.inventory.replaceOne ({item:"Paper"}, {item:"Paper", Instock: [{warehouse:"A", Qty: -}, {warehouse:"B", Qty: + } ] })
Second, Python operation UPDATE statement
# Update a documentdb.inventory.update_one ({"Item":"Paper"}, {"$set": {"Size.uom":"cm","Status":"P"}, "$currentDate": {"lastmodified": True}) # Update multiple documentdb.inventory.update_many ({"Qty": {"$lt": -}}, {"$set": {"Size.uom":"inch","Status":"P"}, "$currentDate": {"lastmodified": True}) # Replace Documentdb.inventory.replace_one ({"Item":"Paper"}, { "Item":"Paper", "Instock": [ {"Warehouse":"A","Qty": -}, {"Warehouse":"B","Qty": +}]})
Third, Java manipulation UPDATE statement
# Update a document
collection.updateone (eq ( " item Span style= "COLOR: #800000" > ", " paper ), combine (set (" size.uom ", " cm " ), Span style= "COLOR: #0000ff" >set ( " status ", " P ), currentdate (" lastmodified "
# update more than one document
collection.updatemany (LT ( " qty ", 50 ), Combine (set ( " size.uom ", " in ", set ( status ", " p ", currentdate ( " LastModified "
# Replace document
collection.replaceone (eq ("item""paper"), Document.parse ("{item: ' Paper ', Instock: [{warehouse: ' A ', qty:60}, {warehouse: ' B ', qty:40}]}"));
MONGODB Learning Article---update operation