Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
Mongoose update loop

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
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!