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

199
Visualizações
When mongoose's save() callback function err part executes

In the below code :

new_user.save(function(err,result){
    if (err){
        console.log(err);
    }
    else{
        console.log(result)
    }
})

I understand that in case of any error while saving the data, if() part will be executed but what in case of no operation performed by save function i.e., the data which it is trying to save in db is already present and hence no insert or update operation is happening?

Now, if() part of callback function will be executed or else()?

Assume that I am adding _id field from my side explicitly to prevent auto generation and inserting new document on the basis of it

While debugging, I got this error - MongoError: E11000 duplicate key error collection:

I have added my own _id field in order to avoid the document duplication when save will be called twice.

If there is any other way to solve this duplication problem, please let me know.

about 4 years ago · Juan Pablo Isaza
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