-6ren">
gpt4 book ai didi

javascript - MongooseError : Query was already executed: Todo. updateOne({ _id: new ObjectId("612df063a8f

转载 作者:行者123 更新时间:2023-12-05 00:31:07 24 4
gpt4 key购买 nike

我将 mongoose 更新到最新版本 (6.0.2),现在我收到此错误并在 .updateOne() 时粉碎应用程序被执行。但是数据库内部的对象更新。我的代码:

async(req,res) => {
await Todo.updateOne(
{_id : req.params.id},
{
$set : {
status : "inactive"
}
},
(updateError) => {
// if updateError exist
if (updateError) {
// print error
printError(updateError);

// response the error
res.status(500).json({
error : "There was a Server Side Error!"
});
} else {
// if error dose not exist
// print message
console.log("|===> 🗂️ Data Was Updated successfully! 🗂️ <====|\n");
// response success
res.json({
message : "Todo Was Update successfully!"
});
}
});
}

最佳答案

尝试将 .clone() 添加到 de updateOne 函数中

async(req,res) => {
await Todo.updateOne(
{_id : req.params.id},
{
$set : {
status : "inactive"
}
},
(updateError) => {
// if updateError exist
if (updateError) {
// print error
printError(updateError);

// response the error
res.status(500).json({
error : "There was a Server Side Error!"
});
} else {
// if error dose not exist
// print message
console.log("|===> 🗂️ Data Was Updated successfully! 🗂️ <====|\n");
// response success
res.json({
message : "Todo Was Update successfully!"
});
}
}).clone();
}
最新版本的 Mongoose 不重复执行
https://mongoosejs.com/docs/migrating_to_6.html#duplicate-query-execution

关于javascript - MongooseError : Query was already executed: Todo. updateOne({ _id: new ObjectId("612df063a8f,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68996929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com