I have a collection with a field 'email' in MongoDB and a unique index on this field. If I try to insert a document with an existing 'email' I get the following error
error: name=MongoError, message=E11000 duplicate key error index: testDB.users.$email_1 dup key: { : "[email protected]" }, index=0, code=11000, errmsg=E11000 duplicate key error index: testDB.users.$email_1 dup key: { : "[email protected]" }
Is there a proper way to get the exact key name from the error message to help identify the exact key that caused the duplicate key error i.e how to extract the 'email' from the error message above?