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

200
Views
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
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!