Wednesday 31 May 2017

if encountered (ao.insertOne) error function,i wish to abort the script, but still i could see the below lines of code displaying in the page

have set unique index on 'name' in mongodb, so if received a duplicate value err invokes, i wish the program to throw below message to the web page but i could only see the last part of the code displaying.

ao.insertOne({name: fields.name, pwd: epass}, function(err){ if(err) { if(err.name=='MongoError' && err.code==11000) { res.write('Username already exisits: \n\n'); res.end(); } res.write('Error in inserting the data: \n\n'); res.end(); }); }); });



via Sridhar Srinivasan

No comments:

Post a Comment