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.