{"action":"opened","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/7271","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/7271/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/7271/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/7271/events","html_url":"https://github.com/Automattic/mongoose/issues/7271","id":383349830,"node_id":"MDU6SXNzdWUzODMzNDk4MzA=","number":7271,"title":"Regression: nested document not set when model initialised with new","user":{"login":"adamreisnz","id":490562,"node_id":"MDQ6VXNlcjQ5MDU2Mg==","avatar_url":"https://avatars0.githubusercontent.com/u/490562?v=4","gravatar_id":"","url":"https://api.github.com/users/adamreisnz","html_url":"https://github.com/adamreisnz","followers_url":"https://api.github.com/users/adamreisnz/followers","following_url":"https://api.github.com/users/adamreisnz/following{/other_user}","gists_url":"https://api.github.com/users/adamreisnz/gists{/gist_id}","starred_url":"https://api.github.com/users/adamreisnz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamreisnz/subscriptions","organizations_url":"https://api.github.com/users/adamreisnz/orgs","repos_url":"https://api.github.com/users/adamreisnz/repos","events_url":"https://api.github.com/users/adamreisnz/events{/privacy}","received_events_url":"https://api.github.com/users/adamreisnz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-22T01:38:05Z","updated_at":"2018-11-22T01:38:05Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"**Do you want to request a *feature* or report a *bug*?**\r\nRegression\r\n\r\nSample code:\r\n\r\n```js\r\nconst mongoose = require('mongoose');\r\nconst {Schema} = mongoose;\r\n\r\nconst ActivityBareSchema = new Schema({\r\n  _id: {\r\n    type: Schema.Types.ObjectId,\r\n    ref: 'Activity',\r\n  },\r\n  name: String,\r\n});\r\n\r\nconst EventSchema = new Schema({\r\n  activity: ActivityBareSchema,\r\n  name: String,\r\n});\r\n\r\nconst data = {\r\n  _id: '5bf606f6471b6056b3f2bfc8',\r\n  name: 'Test',\r\n  activity: {\r\n    _id: '5bf606f6471b6056b3f2bfc9',\r\n    name: 'Activity name',\r\n  },\r\n};\r\n\r\nconst Event = mongoose.model('Event', EventSchema);\r\nconst event = new Event(data, null);\r\n\r\nconsole.log(event);\r\n```\r\n\r\n**What is the current behavior?**\r\nSample script outputs `{ _id: 5bf606f6471b6056b3f2bfc8, name: 'Test' }` with the activity nested document missing.\r\n\r\n**What is the expected behavior?**\r\nIn 5.3.4 (possibly some later versions too), the output included the activity subdocument:\r\n\r\n`{ _id: 5bf606f6471b6056b3f2bfc8,\r\n  name: 'Test',\r\n  activity: { _id: 5bf606f6471b6056b3f2bfc9, name: 'Activity name' } }`\r\n\r\nWe are passing `null` as the second parameter if we don't want to apply any data projection.\r\nThis is useful when we're using the aggregation framework to load documents, and then convert the results to models using `new` instantiation, like so:\r\n\r\n```js\r\nconst events = result.events.map(data => new Event(data, projection));\r\n```\r\n\r\nThe projection that we pass in depends on what the user is querying, and if we want all fields the value for projection is `null`. \r\n\r\nThis was working fine up until 5.3.4, but after updating to 5.3.13 this no longer works.\r\n\r\n**Please mention your node.js, mongoose and MongoDB version.**\r\nNode 8.12.0, MongoDB 4.x."}}
{"actor":{"display_login":"adamreisnz"}}