{"action":"opened","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3883","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3883/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3883/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3883/events","html_url":"https://github.com/Automattic/mongoose/issues/3883","id":133822254,"number":3883,"title":"Update/$set filters out non-strict, deeply nested content","user":{"login":"spamguy","id":5761012,"avatar_url":"https://avatars.githubusercontent.com/u/5761012?v=3","gravatar_id":"","url":"https://api.github.com/users/spamguy","html_url":"https://github.com/spamguy","followers_url":"https://api.github.com/users/spamguy/followers","following_url":"https://api.github.com/users/spamguy/following{/other_user}","gists_url":"https://api.github.com/users/spamguy/gists{/gist_id}","starred_url":"https://api.github.com/users/spamguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spamguy/subscriptions","organizations_url":"https://api.github.com/users/spamguy/orgs","repos_url":"https://api.github.com/users/spamguy/repos","events_url":"https://api.github.com/users/spamguy/events{/privacy}","received_events_url":"https://api.github.com/users/spamguy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-15T21:34:07Z","updated_at":"2016-02-15T21:34:07Z","closed_at":null,"body":"[Assume a schema called 'Season' with an array 'regions'. 'regions' is made up of the subschema 'Order', which is not strictly structured.](https://github.com/spamguy/diplomacy/blob/master/server/models/season.js) My goal is to select and revise an Order item with arbitrary, deeply nested content.\r\n\r\nLet's assume there is a document that looks like `{ regions: [{ r: 'CON' }] }`. Using MongoDB directly, this query results in `{ r: 'CON', unit: { order: { action: 'hold' } } }` as expected:\r\n```\r\ndb.seasons.findAndModify({ 'regions.r': 'CON', _id: ObjectId(\"55e9f39e631812241bb7f579\") },\r\n{ '$set': { 'regions.$.unit': { order: { action: 'hold' } } } }, { new: true, upsert: false, remove: false }\r\n```\r\n\r\nDropping the query into a Mongoose command and running it filters the deeply nested stuff out. That is, running\r\n```\r\nmongoose.model('Season').findOneAndUpdate({\r\n        _id: ObjectId(\"55e9f39e631812241bb7f579\"),\r\n        'regions.r': 'CON'\r\n    }, {\r\n        $set: {\r\n            'regions.$.unit': {\r\n                order: {\r\n                    action: 'hold'\r\n                }\r\n            }\r\n        }\r\n    }, { new: true }, cb);\r\n```\r\nresults in this query printed in debug:\r\n```\r\nseasons.findAndModify({ 'regions.r': 'CON', _id: ObjectId(\"55e9f39e631812241bb7f579\") }) [] { '$setOnInsert': { createdAt: new Date(\"Mon, 15 Feb 2016 20:52:40 GMT\") }, '$set': { updatedAt: new Date(\"Mon, 15 Feb 2016 20:52:40 GMT\") } } { new: true, upsert: false, remove: false }\r\n```\r\n\r\nNotice the total absence of regions.$.unit and everything therein.\r\n\r\nWas running 4.3.6, upgraded to 4.4.3 just now, no difference."}}