{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/5497","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/5497/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/5497/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/5497/events","html_url":"https://github.com/Automattic/mongoose/issues/5497","id":244938550,"number":5497,"title":"Binary buffer saved incorrectly  (breaking change)","user":{"login":"ValYouW","id":4539636,"avatar_url":"https://avatars3.githubusercontent.com/u/4539636?v=4","gravatar_id":"","url":"https://api.github.com/users/ValYouW","html_url":"https://github.com/ValYouW","followers_url":"https://api.github.com/users/ValYouW/followers","following_url":"https://api.github.com/users/ValYouW/following{/other_user}","gists_url":"https://api.github.com/users/ValYouW/gists{/gist_id}","starred_url":"https://api.github.com/users/ValYouW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ValYouW/subscriptions","organizations_url":"https://api.github.com/users/ValYouW/orgs","repos_url":"https://api.github.com/users/ValYouW/repos","events_url":"https://api.github.com/users/ValYouW/events{/privacy}","received_events_url":"https://api.github.com/users/ValYouW/received_events","type":"User","site_admin":false},"labels":[{"id":616301614,"url":"https://api.github.com/repos/Automattic/mongoose/labels/needs%20repro%20script","name":"needs repro script","color":"0e8a16","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/172","html_url":"https://github.com/Automattic/mongoose/milestone/172","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/172/labels","id":2664086,"number":172,"title":"4.11.6","description":"","creator":{"login":"varunjayaraman","id":9360603,"avatar_url":"https://avatars1.githubusercontent.com/u/9360603?v=4","gravatar_id":"","url":"https://api.github.com/users/varunjayaraman","html_url":"https://github.com/varunjayaraman","followers_url":"https://api.github.com/users/varunjayaraman/followers","following_url":"https://api.github.com/users/varunjayaraman/following{/other_user}","gists_url":"https://api.github.com/users/varunjayaraman/gists{/gist_id}","starred_url":"https://api.github.com/users/varunjayaraman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/varunjayaraman/subscriptions","organizations_url":"https://api.github.com/users/varunjayaraman/orgs","repos_url":"https://api.github.com/users/varunjayaraman/repos","events_url":"https://api.github.com/users/varunjayaraman/events{/privacy}","received_events_url":"https://api.github.com/users/varunjayaraman/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":1,"state":"open","created_at":"2017-07-26T22:50:39Z","updated_at":"2017-08-01T01:52:55Z","due_on":"2017-08-06T07:00:00Z","closed_at":null},"comments":3,"created_at":"2017-07-23T21:49:22Z","updated_at":"2017-08-02T08:34:04Z","closed_at":null,"body":"Hi,\r\n\r\nWhen saving GUID to mongo using MongooseBuffer it is being saved incorrectly, this is a breaking change that apparently introduced in version 4.11.2 (I suspect this commit: 1613ef522fb44a2870041b8833bf2f3b36fc45a0)\r\n\r\n I create the value as:\r\n```js\r\nvar buffer = uuidParse.parse(string); // Some guid string\r\nreturn new mongoose.Types.Buffer(buffer).toObject(0x04);\r\n```\r\nAnd the value is being saved in the db as:\r\n```\r\n\"user\" : { \"$binary\" : \"OyRXTOkgQGaO7JL55GgnAg==\", \"$type\" : \"00\" }\r\n```\r\nWhile in version 4.11.1 it is being saved as:\r\n```\r\n\"user\" : UUID(\"3b24574c-e920-4066-8eec-92f9e4682702\")\r\n```\r\n\r\nWhile debugging method `Query.prototype._findAndModify` I can see that the value in `castedDoc` object is different, in 4.11.1 is:\r\n![binary_4_11_1](https://user-images.githubusercontent.com/4539636/28503129-57bfce76-7009-11e7-9252-8a361b7dcb8b.png)\r\n\r\nWhile in 4.11.2 it is:\r\n![binary_4_11_2](https://user-images.githubusercontent.com/4539636/28503130-6225f750-7009-11e7-9df3-76e3910e710d.png)\r\n\r\nI think it happens because of changes in the commit referenced above makes it so `SchemaBuffer.prototype.castForQuery` is not being called.\r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/319606294","html_url":"https://github.com/Automattic/mongoose/issues/5497#issuecomment-319606294","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/5497","id":319606294,"user":{"login":"ValYouW","id":4539636,"avatar_url":"https://avatars3.githubusercontent.com/u/4539636?v=4","gravatar_id":"","url":"https://api.github.com/users/ValYouW","html_url":"https://github.com/ValYouW","followers_url":"https://api.github.com/users/ValYouW/followers","following_url":"https://api.github.com/users/ValYouW/following{/other_user}","gists_url":"https://api.github.com/users/ValYouW/gists{/gist_id}","starred_url":"https://api.github.com/users/ValYouW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ValYouW/subscriptions","organizations_url":"https://api.github.com/users/ValYouW/orgs","repos_url":"https://api.github.com/users/ValYouW/repos","events_url":"https://api.github.com/users/ValYouW/events{/privacy}","received_events_url":"https://api.github.com/users/ValYouW/received_events","type":"User","site_admin":false},"created_at":"2017-08-02T08:34:04Z","updated_at":"2017-08-02T08:34:04Z","body":"@varunjayaraman Hey, the code doesn't need to be synchronized, it doesnt really matter. What I do is 2 independent things:\r\n1. Insert new user with `name=insert` using the `Model.save` method\r\n1. Insert new user with `name=upsert` using `Model.findOneAndUpdate` and `upsert=true`\r\n\r\nNow if you examine in the DB the `foo` property (which is the binary field) you will find that for the 1st user, which was inserted using `Model.save` the value of `foo` is `UUID(\"5fcc7668-2716-4f99-9c71-03e14cbeaa8f\")`.\r\nWhile that for the 2nd user, which was inserted using `Model.findOneAndUpdate` the value of `foo` is `{ \"$binary\" : \"YzA1NDk5ZWEtOWUzNy00NmFhLThlNzMtNGZmN2Q0Nzg5MjYz\", \"$type\" : \"00\" }`\r\n\r\nHere is a screenshot:\r\n![image](https://user-images.githubusercontent.com/4539636/28864782-4bfc884e-7776-11e7-83a1-7732b57c21ed.png)\r\n\r\n"}}
{"actor":{"display_login":"ValYouW"}}