{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/2284","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/2284/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/2284/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/2284/events","html_url":"https://github.com/Automattic/mongoose/issues/2284","id":42149702,"number":2284,"title":"beautiful mongodb native errors (unique - code 11000)","user":{"login":"xpepermint","id":174279,"avatar_url":"https://avatars.githubusercontent.com/u/174279?v=3","gravatar_id":"","url":"https://api.github.com/users/xpepermint","html_url":"https://github.com/xpepermint","followers_url":"https://api.github.com/users/xpepermint/followers","following_url":"https://api.github.com/users/xpepermint/following{/other_user}","gists_url":"https://api.github.com/users/xpepermint/gists{/gist_id}","starred_url":"https://api.github.com/users/xpepermint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xpepermint/subscriptions","organizations_url":"https://api.github.com/users/xpepermint/orgs","repos_url":"https://api.github.com/users/xpepermint/repos","events_url":"https://api.github.com/users/xpepermint/events{/privacy}","received_events_url":"https://api.github.com/users/xpepermint/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/74","html_url":"https://github.com/Automattic/mongoose/milestones/4.5","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/74/labels","id":1418338,"number":74,"title":"4.5","description":"","creator":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars.githubusercontent.com/u/1620265?v=3","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"open_issues":29,"closed_issues":0,"state":"open","created_at":"2015-11-18T16:59:53Z","updated_at":"2016-05-01T05:56:00Z","due_on":"2016-05-13T07:00:00Z","closed_at":null},"comments":22,"created_at":"2014-09-07T19:22:28Z","updated_at":"2016-05-01T08:07:25Z","closed_at":null,"body":"I really miss a mechanism that would create validator-like `unique index` error message. Setting the index of an attribute to `unique: true` will tell mongodb to return ugly error message like this:\r\n\r\n```\r\n{ [MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: mydb-api.users.$email_1  dup key: { : \"my@duplicate.com\" }]\r\n  name: 'MongoError',\r\n  code: 11000,\r\n  err: 'insertDocument :: caused by :: 11000 E11000 duplicate key error index: mydb-api.users.$email_1  dup key: { : \"my@duplicate.com\" }' }\r\n```\r\n\r\nThis message should be treated as validator error message thus we could easily display error messages on a REST service.\r\n\r\n```js\r\n// koa example\r\nindex: function*() {\r\n    try {\r\n      var email = new User(body);\r\n      this.body = yield email.save();\r\n    } catch(e) {\r\n      this.body = e; // nice json errors to display\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/216024618","html_url":"https://github.com/Automattic/mongoose/issues/2284#issuecomment-216024618","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/2284","id":216024618,"user":{"login":"ChrisDillinger","id":5428428,"avatar_url":"https://avatars.githubusercontent.com/u/5428428?v=3","gravatar_id":"","url":"https://api.github.com/users/ChrisDillinger","html_url":"https://github.com/ChrisDillinger","followers_url":"https://api.github.com/users/ChrisDillinger/followers","following_url":"https://api.github.com/users/ChrisDillinger/following{/other_user}","gists_url":"https://api.github.com/users/ChrisDillinger/gists{/gist_id}","starred_url":"https://api.github.com/users/ChrisDillinger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChrisDillinger/subscriptions","organizations_url":"https://api.github.com/users/ChrisDillinger/orgs","repos_url":"https://api.github.com/users/ChrisDillinger/repos","events_url":"https://api.github.com/users/ChrisDillinger/events{/privacy}","received_events_url":"https://api.github.com/users/ChrisDillinger/received_events","type":"User","site_admin":false},"created_at":"2016-05-01T08:07:25Z","updated_at":"2016-05-01T08:07:25Z","body":"Where can I find a list of Mongodb error codes?\r\n`11000`is a duplicate key error code, but where can I find a list of the others?"}}