{"action":"created","issue":{"url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/418","labels_url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/418/labels{/name}","comments_url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/418/comments","events_url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/418/events","html_url":"https://github.com/aldeed/meteor-simple-schema/issues/418","id":96971402,"number":418,"title":"Default values for nested schema","user":{"login":"sungwoncho","id":8265228,"avatar_url":"https://avatars.githubusercontent.com/u/8265228?v=3","gravatar_id":"","url":"https://api.github.com/users/sungwoncho","html_url":"https://github.com/sungwoncho","followers_url":"https://api.github.com/users/sungwoncho/followers","following_url":"https://api.github.com/users/sungwoncho/following{/other_user}","gists_url":"https://api.github.com/users/sungwoncho/gists{/gist_id}","starred_url":"https://api.github.com/users/sungwoncho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sungwoncho/subscriptions","organizations_url":"https://api.github.com/users/sungwoncho/orgs","repos_url":"https://api.github.com/users/sungwoncho/repos","events_url":"https://api.github.com/users/sungwoncho/events{/privacy}","received_events_url":"https://api.github.com/users/sungwoncho/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aldeed/meteor-simple-schema/labels/potential%20bug","name":"potential bug","color":"e11d21"},{"url":"https://api.github.com/repos/aldeed/meteor-simple-schema/labels/waiting%20for%20details","name":"waiting for details","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-07-24T05:55:32Z","updated_at":"2016-01-21T19:23:24Z","closed_at":null,"body":"I am unable to set `defaultValue` for fields in a nested schema.\r\n\r\nHere is an example:\r\n\r\n```javascript\r\nSchema.users = new SimpleSchema({\r\n...\r\n  stats: {\r\n    type: Schema.stats,\r\n  }\r\n});\r\n\r\nSchema.stats = new SimpleSchema({\r\n  topicCount: {\r\n    type: Number,\r\n    defaultValue: 0\r\n  }\r\n});\r\n\r\nMeteor.users.attachSchema(Schema.users);\r\n```\r\n\r\nWhen a user document is created, I expect the `stats.topicCount` to be set to `0` when `stats` is not supplied. Instead, Meteor throws:\r\n\r\n    Stats is required [400]\r\n\r\nIs this an expected behavior, and is there a way to set default values for fields in a nested schema?"},"comment":{"url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/comments/173681377","html_url":"https://github.com/aldeed/meteor-simple-schema/issues/418#issuecomment-173681377","issue_url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/418","id":173681377,"user":{"login":"soitech","id":11201709,"avatar_url":"https://avatars.githubusercontent.com/u/11201709?v=3","gravatar_id":"","url":"https://api.github.com/users/soitech","html_url":"https://github.com/soitech","followers_url":"https://api.github.com/users/soitech/followers","following_url":"https://api.github.com/users/soitech/following{/other_user}","gists_url":"https://api.github.com/users/soitech/gists{/gist_id}","starred_url":"https://api.github.com/users/soitech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soitech/subscriptions","organizations_url":"https://api.github.com/users/soitech/orgs","repos_url":"https://api.github.com/users/soitech/repos","events_url":"https://api.github.com/users/soitech/events{/privacy}","received_events_url":"https://api.github.com/users/soitech/received_events","type":"User","site_admin":false},"created_at":"2016-01-21T19:23:24Z","updated_at":"2016-01-21T19:23:24Z","body":"I also seem to be experiencing this, and I don't think I used to have this issue. Just recently noticed an \"is required\" exception using a schema I've had in place for 8 or 9 months. \r\n\r\nHere are some of the applicable parts:\r\n~~~javascript \r\nStudentsBaseSchema = new SimpleSchema({\r\n    tests: {\r\n\ttype: [Object],\r\n\tdefaultValue: []\r\n    },\r\n\r\n    'tests.$': {\r\n        type: Object,\r\n        optional: true\r\n    }\r\n});\r\n\r\nAlaScoresSchema = new SimpleSchema({\r\n\t'CFC':{\r\n\t\ttype: Number,\r\n\t\tmax: 15,\r\n\t\tmin: -1,\r\n\t\tautoform:{\r\n\t\t\tcapitalize:true,\r\n\t\t\tlabel:'CFC',\r\n\t\t},\r\n\t\tdefaultValue: -1,\r\n\t}\r\n});\r\n\r\nAlaStudentsSchema = new SimpleSchema([StudentsBaseSchema,\r\n  {\r\n    'tests.$.scores':{\r\n      type:AlaScoresSchema\r\n    }\r\n  }\r\n]);\r\n\r\n~~~~~\r\n\r\nSome testing shows it works fine on insert, but not on update, even though clean() is being called in either instance. \r\n"}}