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