{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3078","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3078/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3078/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3078/events","html_url":"https://github.com/Automattic/mongoose/issues/3078","id":88969436,"number":3078,"title":"Model#save ValidationError reported with reference to String indexed Schema","user":{"login":"Panoplos","id":2549985,"avatar_url":"https://avatars.githubusercontent.com/u/2549985?v=3","gravatar_id":"","url":"https://api.github.com/users/Panoplos","html_url":"https://github.com/Panoplos","followers_url":"https://api.github.com/users/Panoplos/followers","following_url":"https://api.github.com/users/Panoplos/following{/other_user}","gists_url":"https://api.github.com/users/Panoplos/gists{/gist_id}","starred_url":"https://api.github.com/users/Panoplos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Panoplos/subscriptions","organizations_url":"https://api.github.com/users/Panoplos/orgs","repos_url":"https://api.github.com/users/Panoplos/repos","events_url":"https://api.github.com/users/Panoplos/events{/privacy}","received_events_url":"https://api.github.com/users/Panoplos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/46","html_url":"https://github.com/Automattic/mongoose/milestones/4.0.7","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/46/labels","id":1152093,"number":46,"title":"4.0.7","description":"","creator":{"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},"open_issues":12,"closed_issues":15,"state":"open","created_at":"2015-06-05T20:58:45Z","updated_at":"2015-07-10T19:54:34Z","due_on":"2015-07-10T07:00:00Z","closed_at":null},"comments":3,"created_at":"2015-06-17T09:41:31Z","updated_at":"2015-07-10T20:15:22Z","closed_at":null,"body":"mongoose@4.0.5\r\nmongodb@2.0.33\r\n\r\nWith the following Schema definitions:\r\n\r\n```js\r\nuser = new mongoose.Schema\r\n  _id:  String\r\n  name: String\r\n\r\nmessage = new mongoose.Schema\r\n  user:     { type: String, ref: 'User' }\r\n  channel:  String\r\n  text:     String\r\n  ts:       Number\r\n\r\nUser = mongoose.model('User', user)\r\nMessage = mongoose.model('Message', message)\r\n\r\nmodule.exports = \r\n  User: User\r\n  Message: Message\r\n```\r\n\r\nWhen I attempt to call `save` in the following manner:\r\n\r\n```js\r\n  new Promise (resolve, reject) =>\r\n    Message.findOne {ts: message.ts}, (err, msg) ->\r\n        if err\r\n          console.error \"Message.findOne( #{ message.ts } ) failed with error '#{ err }'\"\r\n          reject 'database'\r\n        else if not msg\r\n          console.error \"Message.findOne( #{ message.ts } ) returned null...\"\r\n        else\r\n          msg.text = message.text\r\n          msg.save (err, message) ->\r\n            if err\r\n              console.error \"msg.save() failed with error '#{ err }'\"\r\n              reject 'database'\r\n            else\r\n              console.log \"Updated message (id: #{ message._id }) in the database...\"\r\n              resolve message\r\n```\r\n\r\nI get the following error:\r\n\r\n```\r\nmsg.save() failed with error 'ValidationError: Cast to ObjectId failed for value \"[object Object]\" at path \"_id\"'\r\n```\r\n\r\nNote, if I use `update` as follows:\r\n\r\n```js\r\nMessage.update {ts: message.ts}, {$set: {text: message.text}}, (err, msg) ->\r\n```\r\n\r\nIt executes without issue..."},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/120511057","html_url":"https://github.com/Automattic/mongoose/issues/3078#issuecomment-120511057","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3078","id":120511057,"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-07-10T20:15:22Z","updated_at":"2015-07-10T20:15:22Z","body":"Hmm @Panoplos what's the `_id` field in the database? That is, can you go to the mongodb shell and show me what that document looks like? I suspect this is because you have a non-ObjectId `_id` field in the database."}}