Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

213
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda