{"action":"closed","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3569","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3569/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3569/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3569/events","html_url":"https://github.com/Automattic/mongoose/issues/3569","id":116517234,"number":3569,"title":"Wrong coarsion of a String to a Number when creating a new document using findOneAndUpdate() query","user":{"login":"vandervidi","id":6040741,"avatar_url":"https://avatars.githubusercontent.com/u/6040741?v=3","gravatar_id":"","url":"https://api.github.com/users/vandervidi","html_url":"https://github.com/vandervidi","followers_url":"https://api.github.com/users/vandervidi/followers","following_url":"https://api.github.com/users/vandervidi/following{/other_user}","gists_url":"https://api.github.com/users/vandervidi/gists{/gist_id}","starred_url":"https://api.github.com/users/vandervidi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vandervidi/subscriptions","organizations_url":"https://api.github.com/users/vandervidi/orgs","repos_url":"https://api.github.com/users/vandervidi/repos","events_url":"https://api.github.com/users/vandervidi/events{/privacy}","received_events_url":"https://api.github.com/users/vandervidi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-12T10:05:39Z","updated_at":"2015-11-12T10:35:50Z","closed_at":"2015-11-12T10:35:50Z","body":"I have come up with a weird issue when using the findOneAndUpdate() query.\r\nI use these query options: \r\n\r\n    var options = {\r\n\t\tupsert: true,\r\n\t\tsetDefaultsOnInsert : true,\r\n\t\tnew: true\r\n\t};\r\n\r\nMy _id schema attribute is configured as a Number like this:\r\n\r\n     _id: {type: Number, unique: true}\r\n\r\nWhen using the findOneAndUpdate() query in order to create a new document, i pass a STRING value as _id (for example {'_id' : '11111'}).  A new document is created but with an _id of 11112! \r\nWhen coarsing the String to a Number , the _id is , for an unknown reason, incremented by 1.\r\n\r\nThat was so weird and unexpected. So i had to make one more test. \r\nThis time a changed the _id type in the schema to a String\r\n\r\n    _id: {type: String, unique: true}\r\n\r\nExecuted again the same findOneAndUpdate() query. And Whalla , A new document is created with _id that is \"11111\". The value is correct this time and it is not auto incremented. But its a String type...\r\n\r\nWhat my cause the false conversion from String to Number type?\r\n"}}