{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/7830","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/7830/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/7830/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/7830/events","html_url":"https://github.com/Automattic/mongoose/issues/7830","id":446996427,"node_id":"MDU6SXNzdWU0NDY5OTY0Mjc=","number":7830,"title":"set() does not overwrite an entire document as documentation says","user":{"login":"thernstig","id":30827238,"node_id":"MDQ6VXNlcjMwODI3MjM4","avatar_url":"https://avatars1.githubusercontent.com/u/30827238?v=4","gravatar_id":"","url":"https://api.github.com/users/thernstig","html_url":"https://github.com/thernstig","followers_url":"https://api.github.com/users/thernstig/followers","following_url":"https://api.github.com/users/thernstig/following{/other_user}","gists_url":"https://api.github.com/users/thernstig/gists{/gist_id}","starred_url":"https://api.github.com/users/thernstig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thernstig/subscriptions","organizations_url":"https://api.github.com/users/thernstig/orgs","repos_url":"https://api.github.com/users/thernstig/repos","events_url":"https://api.github.com/users/thernstig/events{/privacy}","received_events_url":"https://api.github.com/users/thernstig/received_events","type":"User","site_admin":false},"labels":[{"id":29038163,"node_id":"MDU6TGFiZWwyOTAzODE2Mw==","url":"https://api.github.com/repos/Automattic/mongoose/labels/enhancement","name":"enhancement","color":"02d7e1","default":true},{"id":154676778,"node_id":"MDU6TGFiZWwxNTQ2NzY3Nzg=","url":"https://api.github.com/repos/Automattic/mongoose/labels/fixed?","name":"fixed?","color":"0052cc","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/303","html_url":"https://github.com/Automattic/mongoose/milestone/303","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/303/labels","id":4210191,"node_id":"MDk6TWlsZXN0b25lNDIxMDE5MQ==","number":303,"title":"5.6","description":"","creator":{"login":"vkarpov15","id":1620265,"node_id":"MDQ6VXNlcjE2MjAyNjU=","avatar_url":"https://avatars2.githubusercontent.com/u/1620265?v=4","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":0,"closed_issues":18,"state":"closed","created_at":"2019-04-08T14:53:28Z","updated_at":"2019-06-15T19:32:09Z","due_on":"2019-06-14T07:00:00Z","closed_at":"2019-06-15T19:32:09Z"},"comments":9,"created_at":"2019-05-22T08:19:38Z","updated_at":"2019-06-19T13:45:09Z","closed_at":"2019-06-14T16:40:31Z","author_association":"NONE","body":"**Do you want to request a *feature* or report a *bug*?**\r\nDocumentation bug?\r\n\r\n**What is the current behavior?**\r\nAccording to https://mongoosejs.com/docs/documents.html#overwriting it says:\r\n\r\n> You can overwrite an entire document using .set(). This is handy if you want to change what document is being saved in middleware.\r\n\r\nAs an example:\r\n\r\n```javascript\r\nTank.findById(id, function (err, tank) {\r\n  if (err) return handleError(err);\r\n  // Now `otherTank` is a copy of `tank`\r\n  otherTank.set(tank);\r\n});\r\n```\r\n\r\nIf otherTank contains some keys that tank does not have, those are retained in the new version of otherTank. As such, the **entire** document is not overwritten, but rather only those paths that both documents contained.\r\n\r\nA question tied to this:\r\nWhat I tried to achieve was to implement a HTTP PUT call where a user supplies just the parts they want in the new document and the rest gets overwritten. I assume the only way to overwrite everything and still get validation is to do a const test = new X() followed by a test.validate() and then a replaceOne() on the old id? The problems with this approach is that version does not increase, and timestamps (if enabled on the schema) replaces createdAt with the timestamp of when the replacement happens. So I am actually confused how to implement a HTTP PUT properly."},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/503567133","html_url":"https://github.com/Automattic/mongoose/issues/7830#issuecomment-503567133","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/7830","id":503567133,"node_id":"MDEyOklzc3VlQ29tbWVudDUwMzU2NzEzMw==","user":{"login":"vkarpov15","id":1620265,"node_id":"MDQ6VXNlcjE2MjAyNjU=","avatar_url":"https://avatars2.githubusercontent.com/u/1620265?v=4","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":"2019-06-19T13:45:09Z","updated_at":"2019-06-19T13:45:09Z","author_association":"COLLABORATOR","body":"@thernstig [using `save()` is the best way to update the document](https://masteringjs.io/tutorials/mongoose/update), you're right. But Mongoose versioning only kicks in when you modify an array in place using `push()`, `pull()`, etc. If you always overwrite the entire array using `set()`, versioning won't do anything."}}
{"actor":{"display_login":"vkarpov15"}}