[英]How to display an html string stored in the mongodb using express
[英]How to edit stored data in MongoDB using Express?
如何以 express 作为后端更新 MongoDB 中的文档?
这是后端 API
app.post("/update",(req,res)=>{
const id=req.body.id;
console.log(id);
contact.updateOne({'_id':id},req.body,(err,res)=>{
if(err) throw err
console.log('data edited....')
});
res.redirect("/show");
console.log("done..");
});
我认为您要求更新文档
app.patch("/update", (req, res) => {
const id = req.body.id;
console.log(id);
contact.findByIdAndUpdate(id, req.body, (err, res) => {
if (err) throw err
console.log('data edited....')
});
res.redirect("/show");
console.log("done..");
});
希望对你有帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.