demo_update_one.js:
var MongoClient = require('mongodb').MongoClient; var url = "mongodb://localhost:27017/"; MongoClient.connect(url, function(err, db) { if (err) throw err; var dbo = db.db("mydb"); var myquery = { address: "Valley 345" }; var newvalues = { $set: { name: "Michael", address: "Canyon 123" } }; dbo.collection("customers").updateOne(myquery, newvalues, function(err, res) { if (err) throw err; console.log("1 document updated"); db.close(); }); });
C:\Users\My Name>node demo_update_one.js
1 document updated