{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/4349","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/4349/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/4349/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/4349/events","html_url":"https://github.com/Automattic/mongoose/issues/4349","id":166524357,"number":4349,"title":"_id as ObjectId shouldn't throw error","user":{"login":"gitawego","id":438120,"avatar_url":"https://avatars.githubusercontent.com/u/438120?v=3","gravatar_id":"","url":"https://api.github.com/users/gitawego","html_url":"https://github.com/gitawego","followers_url":"https://api.github.com/users/gitawego/followers","following_url":"https://api.github.com/users/gitawego/following{/other_user}","gists_url":"https://api.github.com/users/gitawego/gists{/gist_id}","starred_url":"https://api.github.com/users/gitawego/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gitawego/subscriptions","organizations_url":"https://api.github.com/users/gitawego/orgs","repos_url":"https://api.github.com/users/gitawego/repos","events_url":"https://api.github.com/users/gitawego/events{/privacy}","received_events_url":"https://api.github.com/users/gitawego/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-20T08:19:41Z","updated_at":"2016-07-22T14:35:56Z","closed_at":null,"body":"in latest version (4.5.5), if _id is converted to ObjectId before query:\r\n```js\r\n    if ('_id' in $query) {\r\n       $query._id = objectID($query._id);\r\n    }\r\n   Model.aggregate([{\r\n     $match:$query\r\n   }]).allowDiskUse(true).cursor({ batchSize: 100 }).exec();\r\n```\r\nmongoose throws error:\r\n```\r\nTypeError: Argument must be a string\r\n    at TypeError (native)\r\n    at Buffer.write (buffer.js:763:21)\r\n    at serializeObjectId (path/to/node_modules/mongoose/node_modules/bson/lib/bson/parser/serializer.js:242:10)\r\n    at serializeInto (path/to/node_modules/mongoose/node_modules/bson/lib/bson/parser/serializer.js:699:17)\r\n```\r\nI think this is too strict, if ``_id`` is already an ObjectId,  mongoose should simply stop casting it to ObjectId."},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/234560919","html_url":"https://github.com/Automattic/mongoose/issues/4349#issuecomment-234560919","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/4349","id":234560919,"user":{"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},"created_at":"2016-07-22T14:35:56Z","updated_at":"2016-07-22T14:35:56Z","body":"What is `query._id` in your example? Mongoose doesn't do any casting on `.aggregate()` stages..."}}
{"actor":{"display_login":"vkarpov15"}}