{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3364","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3364/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3364/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3364/events","html_url":"https://github.com/Automattic/mongoose/issues/3364","id":106003715,"number":3364,"title":"4.1.6 does not cast strings to ObjectId in queries for schema sub-arrays","user":{"login":"Crotery","id":2670463,"avatar_url":"https://avatars.githubusercontent.com/u/2670463?v=3","gravatar_id":"","url":"https://api.github.com/users/Crotery","html_url":"https://github.com/Crotery","followers_url":"https://api.github.com/users/Crotery/followers","following_url":"https://api.github.com/users/Crotery/following{/other_user}","gists_url":"https://api.github.com/users/Crotery/gists{/gist_id}","starred_url":"https://api.github.com/users/Crotery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Crotery/subscriptions","organizations_url":"https://api.github.com/users/Crotery/orgs","repos_url":"https://api.github.com/users/Crotery/repos","events_url":"https://api.github.com/users/Crotery/events{/privacy}","received_events_url":"https://api.github.com/users/Crotery/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-09-11T12:51:15Z","updated_at":"2015-10-14T16:35:01Z","closed_at":"2015-10-14T05:45:12Z","body":"We have Schema:\r\n```js\r\n{\r\naaa: Number,\r\nconstr:     [\r\n            {\r\n                no:       Number,\r\n                sum:   Number,            \r\n            }\r\n        ],\r\n}, {\r\n collection: \"orders\",\r\n        _id:        true,\r\n       \r\n}\r\n```\r\nThis code works in 3.8, but doest not work in 4.1.6 (it can't find obj to update and returns null)\r\n```js\r\n var c = {\r\n            _id:            '55f2bf1182aeecc96e1a7389',\r\n            \"constr._id\":    '55f2bf1182aeecc96e1a5522'\r\n        };\r\n\r\nModel.findOneAndUpdate(c, {aaa:1, \"constr.$.sum\":3})\r\n```\r\nSeems like 4x mongoose is not casting strings to ObjectId for sub-schema arrays, because this query works fine in 4.1.6 and 3.8:\r\n```js\r\n var c = {\r\n            _id:            '55f2bf1182aeecc96e1a7389',\r\n            \"constr._id\":  new Mongoose.Types.ObjectId('55f2bf1182aeecc96e1a5522')\r\n        };\r\n```\r\n\r\nIf we add explicitly _id declarations in Shema and sum-array Shema, nothing changes, auto-casting for constr._id does not work."},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/148108775","html_url":"https://github.com/Automattic/mongoose/issues/3364#issuecomment-148108775","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3364","id":148108775,"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":"2015-10-14T16:35:01Z","updated_at":"2015-10-14T16:35:01Z","body":"No it'll just overwrite"}}