{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3171","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3171/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3171/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3171/events","html_url":"https://github.com/Automattic/mongoose/issues/3171","id":95591416,"number":3171,"title":"Model.update with $rename does not seem to work","user":{"login":"JedWatson","id":872310,"avatar_url":"https://avatars.githubusercontent.com/u/872310?v=3","gravatar_id":"","url":"https://api.github.com/users/JedWatson","html_url":"https://github.com/JedWatson","followers_url":"https://api.github.com/users/JedWatson/followers","following_url":"https://api.github.com/users/JedWatson/following{/other_user}","gists_url":"https://api.github.com/users/JedWatson/gists{/gist_id}","starred_url":"https://api.github.com/users/JedWatson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JedWatson/subscriptions","organizations_url":"https://api.github.com/users/JedWatson/orgs","repos_url":"https://api.github.com/users/JedWatson/repos","events_url":"https://api.github.com/users/JedWatson/events{/privacy}","received_events_url":"https://api.github.com/users/JedWatson/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/49","html_url":"https://github.com/Automattic/mongoose/milestones/3.8.34","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/49/labels","id":1202869,"number":49,"title":"3.8.34","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":0,"closed_issues":2,"state":"closed","created_at":"2015-07-10T18:18:04Z","updated_at":"2015-07-20T15:38:16Z","due_on":"2015-07-20T04:00:00Z","closed_at":"2015-07-20T15:38:16Z"},"comments":14,"created_at":"2015-07-17T05:41:54Z","updated_at":"2015-10-29T14:58:11Z","closed_at":"2015-07-20T15:37:48Z","body":"> note: I'm using 3.8.33, so if this is resolved in 4.x my apologies, I'm not able to upgrade the project I'm working on yet...\r\n\r\nI've got a field in a collection that I want to rename, and have been able to do it successfully from the `mongo` cli using the following:\r\n\r\n```\r\ndb.agents.update({}, { $rename: { \"state\": \"contactStatus\" } }, { multi: true })\r\n```\r\n\r\nHowever, I want to write this into an update script so it is applied to my staging and production environments when the new version of my app is released.\r\n\r\nSince I'm using mongoose, it seems I should be able to use the `Model.update` method to achieve the same:\r\n\r\n```\r\nAgentModel.update(\r\n  { },\r\n  { $rename: { state: 'contactStatus' } },\r\n  { multi: true },\r\n  function(err, raw) { console.log(err, raw); }\r\n);\r\n```\r\n\r\nThis doesn't seem to have any effect on the data, however, and the value of `raw` when logged to the console is `0`.\r\n\r\nShould this update query be supported by Mongoose? I know that the `update` query is rewritten to `{ $set: { update } }` when `overwrite: false` (default), but the docs say:\r\n\r\n> All top level keys which are not atomic operation names\r\n\r\n... which I had expected would mean `$rename` would work as expected.\r\n\r\nNot sure if this is related to #3027? No error is being thrown.\r\n\r\nAny guidance would be appreciated, and if there's further debug information I can provide please let me know."},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/152205984","html_url":"https://github.com/Automattic/mongoose/issues/3171#issuecomment-152205984","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3171","id":152205984,"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-29T14:58:11Z","updated_at":"2015-10-29T14:58:11Z","body":"Hmm can you double-check your version of mongoose for me and run mongoose debug mode `require('mongoose').set('debug', true);` to show me what query is being sent to mongodb?"}}