{"action":"closed","issue":{"url":"https://api.github.com/repos/blakehaswell/mongoose-unique-validator/issues/41","repository_url":"https://api.github.com/repos/blakehaswell/mongoose-unique-validator","labels_url":"https://api.github.com/repos/blakehaswell/mongoose-unique-validator/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/blakehaswell/mongoose-unique-validator/issues/41/comments","events_url":"https://api.github.com/repos/blakehaswell/mongoose-unique-validator/issues/41/events","html_url":"https://github.com/blakehaswell/mongoose-unique-validator/issues/41","id":133343304,"number":41,"title":"Validation does not work when modifying existing document","user":{"login":"rshov","id":10855603,"avatar_url":"https://avatars.githubusercontent.com/u/10855603?v=3","gravatar_id":"","url":"https://api.github.com/users/rshov","html_url":"https://github.com/rshov","followers_url":"https://api.github.com/users/rshov/followers","following_url":"https://api.github.com/users/rshov/following{/other_user}","gists_url":"https://api.github.com/users/rshov/gists{/gist_id}","starred_url":"https://api.github.com/users/rshov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rshov/subscriptions","organizations_url":"https://api.github.com/users/rshov/orgs","repos_url":"https://api.github.com/users/rshov/repos","events_url":"https://api.github.com/users/rshov/events{/privacy}","received_events_url":"https://api.github.com/users/rshov/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-02-12T21:06:14Z","updated_at":"2016-02-20T00:09:18Z","closed_at":"2016-02-20T00:09:18Z","body":"When I change the name field of an existing document to be the same as another document, then I get the MongoDB error: E11000 duplicate key error index\r\n\r\nThe unique validator works for me when I create a new document, but not when modifying an existing document. Should it work for existing documents? I'm assuming it should.\r\n\r\nMy code is doing:\r\n```javascript\r\nProject.findById(projectId, function (err, project) {\r\n    project.name = req.body.name;\r\n    project.save( function (err) {\r\n        // Here I get a MongoDB error instead of a Mongoose error!\r\n    });\r\n});\r\n```\r\n\r\nThanks for any help"}}