app.patch('/update', async(req, res) => {
await client.connect();
db = await client.db("Lab3");
let collection = await db.collection("students");
let susername = req.body.username
let result = await collection.findOneAndUpdate(
{username : susername}, req.body, {new: true}
)
res.send(result).status(200);
});
Hi everyone, I’m currenly facing a problem when I want to update data to my mongoDB database. I try to not specified what to update from the user, but let the user choose what to update. So that my findOneandUpdate parameter will be username as filter, req.body as the content to update to the database. Can anyone help me to solve this problem? Thank you so much!
Hello, @turivishal. The error before I get is [Update document requires atomic operators]. After I entering the $set parameter, the program works successfully! Thanks for your helping, I have find for the way to solve this error for hours.