Error "DocumentNotFoundError: No document found for query "{ _id:xxx}
Error "DocumentNotFoundError: No document found for query "{ _id:xxx}
我克隆了对象“preventivo”,
当我 运行 此代码时,出现以下错误:
(节点:24548)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):DocumentNotFoundError:在模型“preventivi”上找不到查询“{_id:5ff6110e27bbf25fe45ce2b5}”的文档
我不明白错误,你能帮我吗?
我使用 node + mongoose + handlebars
谢谢
//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
我克隆了对象“preventivo”, 当我 运行 此代码时,出现以下错误: (节点:24548)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):DocumentNotFoundError:在模型“preventivi”上找不到查询“{_id:5ff6110e27bbf25fe45ce2b5}”的文档 我不明白错误,你能帮我吗? 我使用 node + mongoose + handlebars 谢谢
//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