I'm new to the world of mongoose and NodeJs, my problem occurs when I perform an update, effectively the update is carried out in the database but time later it happens again.
I perform the update as follows
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);
};
this is the log of my aplication when i update a 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
}
You're not awaiting the result of your deleteLead call. This means that your controller will just send off the request and move on.
When the request does resolve, it may happen while another controller is in the process of running, which would result in query results being logged in a way that looks like your controller hit MongoDB more than once, when it actually didn't.