我克隆了对象“preventivo”,
当我运行此代码时,出现以下错误:
(节点:24548)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):DocumentNotFoundError:在模型“preventivi”上找不到查询“{_id:5ff6110e27bbf25fe45ce2b5}”的文档
我不明白这个错误,你能帮我吗?
我使用节点+猫鼬+车把
谢谢
//ROUTE CLONA PREVENTIVO
app.post('/preventivi/dbpreventivi/:id/clone' ,accessoSicuro,(req , res) =>{
Preventivi.findOne({
_id: req.params.id
})
.then(preventivo => {
var newdoc = new Preventivi(preventivo);
newdoc._id = mongoose.Types.ObjectId();
delete newdoc.__v;
newdoc.save();
console.log(newdoc._id)
req.flash("msg_successo", "Preventivo clonato correttamente");
res.redirect("/preventivi/dbpreventivi");
});
});
//fine route clona preventivo
Html:
<form action="/preventivi/dbpreventivi/{{_id}}/clone?_method=POST" method="post">
<input type="hidden" name="_method" value="POST">
<input onclick="return confirm('Vuoi clonare il preventivo: {{cliente}} {{codice}} ?');" type="submit" class="btn btn-warning btn-sm" value="Clona">
</form>
您可以尝试添加 newdoc.isNew = true :
//ROUTE CLONA PREVENTIVO
app.post('/preventivi/dbpreventivi/:id/clone' ,accessoSicuro,(req , res) =>{
Preventivi.findOne({
_id: req.params.id
})
.then(preventivo => {
var newdoc = new Preventivi(preventivo);
newdoc._id = mongoose.Types.ObjectId();
newdoc.isNew = true;
newdoc.save();
console.log(newdoc._id)
req.flash("msg_successo", "Preventivo clonato correttamente");
res.redirect("/preventivi/dbpreventivi");
});
});
//fine route clona preventivo
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)