Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda