{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/6691","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/6691/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/6691/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/6691/events","html_url":"https://github.com/Automattic/mongoose/issues/6691","id":339208209,"node_id":"MDU6SXNzdWUzMzkyMDgyMDk=","number":6691,"title":"Unable to set array to `null` as default","user":{"login":"sebastian-nowak","id":5895458,"node_id":"MDQ6VXNlcjU4OTU0NTg=","avatar_url":"https://avatars3.githubusercontent.com/u/5895458?v=4","gravatar_id":"","url":"https://api.github.com/users/sebastian-nowak","html_url":"https://github.com/sebastian-nowak","followers_url":"https://api.github.com/users/sebastian-nowak/followers","following_url":"https://api.github.com/users/sebastian-nowak/following{/other_user}","gists_url":"https://api.github.com/users/sebastian-nowak/gists{/gist_id}","starred_url":"https://api.github.com/users/sebastian-nowak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebastian-nowak/subscriptions","organizations_url":"https://api.github.com/users/sebastian-nowak/orgs","repos_url":"https://api.github.com/users/sebastian-nowak/repos","events_url":"https://api.github.com/users/sebastian-nowak/events{/privacy}","received_events_url":"https://api.github.com/users/sebastian-nowak/received_events","type":"User","site_admin":false},"labels":[{"id":179219,"node_id":"MDU6TGFiZWwxNzkyMTk=","url":"https://api.github.com/repos/Automattic/mongoose/labels/docs","name":"docs","color":"444444","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-07-08T08:36:26Z","updated_at":"2018-07-08T12:22:30Z","closed_at":"2018-07-08T12:22:30Z","author_association":"NONE","body":"**Do you want to request a *feature* or report a *bug*?**\r\n\r\nBug in the latest mongoose version (5.2.1)\r\n\r\n**What is the current behavior?**\r\n\r\nSchemas ignore `default: null` for arrays, empty array is created instead.\r\n\r\n```js\r\nconst schema = new mongoose.Schema({\r\n  arrayThatShouldBeNull: {\r\n    type: [String],\r\n    default: null,\r\n    required: false\r\n  },\r\n\r\n  arrayThatShouldContainTwoEntries: {\r\n    type: [String],\r\n    default: ['asd', '123'],\r\n    required: false\r\n  }\r\n}, {\r\n  minimize: false // not sure if relevant\r\n});\r\n\r\nconst Model = mongoose.model('test', schema);\r\nconst instance = new Model();\r\n\r\nexpect(instance.arrayThatShouldBeNull).to.be.null; // fails\r\nexpect(instance.arrayThatShouldContainTwoEntries).to.deep.equal(['asd', '123']); // passes\r\n```\r\n\r\n**What is the expected behavior?**\r\n\r\n`instance.arrayThatShouldBeNull` should be set to null, but instead an empty array is created"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/403284082","html_url":"https://github.com/Automattic/mongoose/issues/6691#issuecomment-403284082","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/6691","id":403284082,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzI4NDA4Mg==","user":{"login":"lineus","id":6015453,"node_id":"MDQ6VXNlcjYwMTU0NTM=","avatar_url":"https://avatars3.githubusercontent.com/u/6015453?v=4","gravatar_id":"","url":"https://api.github.com/users/lineus","html_url":"https://github.com/lineus","followers_url":"https://api.github.com/users/lineus/followers","following_url":"https://api.github.com/users/lineus/following{/other_user}","gists_url":"https://api.github.com/users/lineus/gists{/gist_id}","starred_url":"https://api.github.com/users/lineus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lineus/subscriptions","organizations_url":"https://api.github.com/users/lineus/orgs","repos_url":"https://api.github.com/users/lineus/repos","events_url":"https://api.github.com/users/lineus/events{/privacy}","received_events_url":"https://api.github.com/users/lineus/received_events","type":"User","site_admin":false},"created_at":"2018-07-08T12:22:29Z","updated_at":"2018-07-08T12:22:29Z","author_association":"COLLABORATOR","body":"opened PR #6695 for this."}}
{"actor":{"display_login":"lineus"}}