I have user schema with 2 unique fields(email and username) and when i try to create new user with duplicated field I have that error
{
"error": {
"code": 11000,
"index": 0,
"errmsg": "E11000 duplicate key error collection: InstaClone.users index: email_1 dup key: { : \"baidario.ua@gmail.com\" }",
"op": {
"hashedPassword": "$2a$10$eaMym5AMibJlGOSBV3/DHOXPhSoMMDTNwxGcSOn4tEPg07htyQ2Ey",
"email": "baidario.ua@gmail.com",
"username": "baidario",
"fullName": "Roman Baida",
"_id": "58d3a8acdc57641e30e9027a",
"created": "2017-03-23T10:50:49.188Z",
"__v": 0
}
}
}
How I can get duplicated filed name? Only way I see is to parse errmsg
field. Maybe someone know better way?
find()
returns and thecreate()
is executed (resulting in the duplicate key error). – robertklep