I need to update the data from client side in mongodb but I can see clicked updated Id value in node js but it does not update in mongodb wat to do.. help me to update the values in mongo db using id values
router.post('/datapassfup', (req, res) => {
console.log("updated values are",req.body)
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mohan");
var myquery = { id: req.body.id };
var newvalues = { $set: {name: req.body.name, username:
req.body.username } };
dbo.collection("customers").updateMany(myquery,newvalues,
function(err, res) {
if (err) throw err;
console.log("1 document updated");
db.close();
});
});
});
{ id: req.body.id };should be{_id: req.body.id };db.collection.deleteOne({_id: req.body.id})customerscollection look like, can theidfield map to may documents or it's unique? If the latter is true thenupdateManyis not appropriate for that case.