{"action":"closed","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3133","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3133/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3133/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3133/events","html_url":"https://github.com/Automattic/mongoose/issues/3133","id":92686974,"number":3133,"title":"Projections do not apply to discriminator properties as one would expect","user":{"login":"jlchereau","id":2556751,"avatar_url":"https://avatars.githubusercontent.com/u/2556751?v=3","gravatar_id":"","url":"https://api.github.com/users/jlchereau","html_url":"https://github.com/jlchereau","followers_url":"https://api.github.com/users/jlchereau/followers","following_url":"https://api.github.com/users/jlchereau/following{/other_user}","gists_url":"https://api.github.com/users/jlchereau/gists{/gist_id}","starred_url":"https://api.github.com/users/jlchereau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlchereau/subscriptions","organizations_url":"https://api.github.com/users/jlchereau/orgs","repos_url":"https://api.github.com/users/jlchereau/repos","events_url":"https://api.github.com/users/jlchereau/events{/privacy}","received_events_url":"https://api.github.com/users/jlchereau/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Automattic/mongoose/labels/can't%20reproduce","name":"can't reproduce","color":"bfdadc"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/54","html_url":"https://github.com/Automattic/mongoose/milestones/4.1.4","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/54/labels","id":1251783,"number":54,"title":"4.1.4","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":15,"closed_issues":15,"state":"open","created_at":"2015-08-12T14:08:51Z","updated_at":"2015-08-28T17:58:21Z","due_on":"2015-08-28T04:00:00Z","closed_at":null},"comments":3,"created_at":"2015-07-02T17:11:17Z","updated_at":"2015-08-28T17:58:21Z","closed_at":"2015-08-28T17:58:21Z","body":"This is the base schema:\r\n```\r\nfunction VersionBaseSchema() {\r\n    mongoose.Schema.apply(this, arguments);\r\n    this.options.discriminatorKey = 'type';\r\n    this.add({\r\n        _summaryId          : { type: mongoose.Schema.Types.ObjectId, ref: 'Summary', required: true },\r\n        _userId             : { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },\r\n        language            : { type: String, required: true, validate: schemaValidators.languageISOCode },\r\n        state               : { type: Number, required: true, validate: schemaValidators.state },\r\n        updated             : { type: Date, required: true, default: Date.now }\r\n    });\r\n}\r\nvar versionSchema = new VersionBaseSchema();\r\n```\r\n\r\nThis is the discriminator:\r\n```\r\nvar testSchema = new VersionBaseSchema({\r\n    stream    : {\r\n        pages           : { type: [pageSchema], default:[] },\r\n        style           : { type: String, trim: true }\r\n    }\r\n});\r\nmodel.discriminator('Test', testSchema);\r\n```\r\n\r\nThis is the subdocument:\r\n```\r\nvar pageSchema = new mongoose.Schema({\r\n    components          : { type: [componentSchema], default:[] },\r\n    style               : { type: String, trim: true }\r\n});\r\n```\r\n\r\nThe defect is illustrated by the following request:\r\n```\r\nvar Version = mongoose.model('Version'),\r\n    TypedVersion = Version.discriminators[version.type];\r\n\r\nTypedVersion.findOne({ language: req.params.language, _summaryId: req.params.summaryId, _id: req.params.versionId }, { language: 1 }, function(error, version) {\r\n         ...       \r\n});\r\n```\r\n\r\nthe returned version has:\r\n- _id as expected,\r\n- language as expected,\r\n\r\nbut also:\r\n- type (or __t) which is unexpected, especially since {type: 0} removes the type from the projection;\r\n- stream with its default value, {pages: []}, whatever the value in database, which is also unexpected.\r\n\r\n"}}