我是猫鼬和NodeJs世界的新手,当我执行更新时,我的问题发生了,有效地更新是在数据库中进行的,但时间过了又发生了。
我执行如下更新
router.post("/deleteLead", (req, res) => {
console.log("----------- delete lead -------");
const body = req.body;
deleteLead(body);
});
async function deleteLead(body) {
const id_delete = body.leads.delete[0].id;
const deleteLead = await Model_Lead.updateOne(
{ id: id_delete },
{
is_deleted: true,
}
);
console.log(deleteLead);
};
这是我的应用程序的日志,当我更新一个lead
----------- delete Lead -------
{
acknowledged: true,
modifiedCount: 1,
upsertedId: null,
upsertedCount: 0,
matchedCount: 1
}
{
acknowledged: true,
modifiedCount: 1,
upsertedId: null,
upsertedCount: 0,
matchedCount: 1
}
----------- delete Lead -------
{
acknowledged: true,
modifiedCount: 1,
upsertedId: null,
upsertedCount: 0,
matchedCount: 1
}
----------- delete Lead -------
{
acknowledged: true,
modifiedCount: 1,
upsertedId: null,
upsertedCount: 0,
matchedCount: 1
}
----------- delete Lead -------
{
acknowledged: true,
modifiedCount: 1,
upsertedId: null,
upsertedCount: 0,
matchedCount: 1
}
您没有等待deleteLead
呼叫的结果。这意味着你的控制器将发送请求并继续前进。
当请求解决时,它可能发生在另一个控制器正在运行的过程中,这将导致查询结果以看起来像的方式被记录,你的控制器不止一次命中MongoDB,当它实际上没有。