{"action":"opened","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3179","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3179/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3179/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3179/events","html_url":"https://github.com/Automattic/mongoose/issues/3179","id":96129348,"number":3179,"title":"Default set on sub-property causes its parent to appear in result even when not selected","user":{"login":"alobodig","id":1733093,"avatar_url":"https://avatars.githubusercontent.com/u/1733093?v=3","gravatar_id":"","url":"https://api.github.com/users/alobodig","html_url":"https://github.com/alobodig","followers_url":"https://api.github.com/users/alobodig/followers","following_url":"https://api.github.com/users/alobodig/following{/other_user}","gists_url":"https://api.github.com/users/alobodig/gists{/gist_id}","starred_url":"https://api.github.com/users/alobodig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alobodig/subscriptions","organizations_url":"https://api.github.com/users/alobodig/orgs","repos_url":"https://api.github.com/users/alobodig/repos","events_url":"https://api.github.com/users/alobodig/events{/privacy}","received_events_url":"https://api.github.com/users/alobodig/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-20T18:36:28Z","updated_at":"2015-07-20T18:36:28Z","closed_at":null,"body":"When a property is defined as an object containing a sub-property with a default, e.g.:\r\n```\r\n{\r\n  property: {\r\n     example: { type: String },\r\n     sub: { type: String, default: 'hello' }\r\n  }\r\n}\r\n```\r\nReturned objects contain that property as an empty object when it is not selected.\r\n```\r\ntest.findOne({}, 'example' ...);\r\n// Returns: { _id: ObjectId('...'), sub: { } }\r\n````\r\nHowever, explicitly deselecting it does remove it from the result.\r\n```\r\ntest.findOne({}, '-sub' ...);\r\n// Returns: { _id: ObjectId('...'), __v: 1 }\r\n````\r\nThis may be tangentially related to #1022, which was an issue with properties selected in the schema definition. \r\n\r\nFull test case:\r\n```\r\nvar schema = new mongoose.Schema({\r\n        embedded: {\r\n           field: { type: Number, default: 1, select: false  }\r\n        }\r\n});\r\n\r\nvar Test = mongoose.model('Test', schema);\r\nvar a = new Test();\r\na.save(function(err) {\r\n        Test.find({ _id: a._id }, '_id', function(err, b) {\r\n                console.log(b); // b will contain an \"field\" as an empty object\r\n        });\r\n});\r\n```"}}