{"action":"opened","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/4499","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/4499/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/4499/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/4499/events","html_url":"https://github.com/Automattic/mongoose/issues/4499","id":175700869,"number":4499,"title":"Field '__v' gets initialized with non-numeric type NULL","user":{"login":"BenBestmann","id":3327832,"avatar_url":"https://avatars.githubusercontent.com/u/3327832?v=3","gravatar_id":"","url":"https://api.github.com/users/BenBestmann","html_url":"https://github.com/BenBestmann","followers_url":"https://api.github.com/users/BenBestmann/followers","following_url":"https://api.github.com/users/BenBestmann/following{/other_user}","gists_url":"https://api.github.com/users/BenBestmann/gists{/gist_id}","starred_url":"https://api.github.com/users/BenBestmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BenBestmann/subscriptions","organizations_url":"https://api.github.com/users/BenBestmann/orgs","repos_url":"https://api.github.com/users/BenBestmann/repos","events_url":"https://api.github.com/users/BenBestmann/events{/privacy}","received_events_url":"https://api.github.com/users/BenBestmann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-08T09:01:12Z","updated_at":"2016-09-08T09:01:12Z","closed_at":null,"body":"When trying to perform a `.()save` on a document of my contact model I get the following error:\r\n\r\n    Cannot apply $inc to a value of non-numeric type. {_id: ObjectId('57d0063348b748000369a7bd')} has the field '__v' of non-numeric type NULL\r\n\r\nThe schema looks like this:\r\n\r\n    name: { type: String, minlength: 1, maxlength: 50, required: true },\r\n    emails: [{\r\n        _id: false,\r\n        label: { type: String, minlength: 2, maxlength: 20, default: 'primary', required: true },\r\n        email: { type: String, validate: Validators.emailValidator, required: true }\r\n    }],\r\n    phones: [{\r\n        _id: false,\r\n        label: { type: String, minlength: 2, maxlength: 20, default: 'primary', required: true },\r\n        number: { type: String, validate: Validators.phoneValidator, required: true }\r\n    }],\r\n    addresses: [{\r\n        _id: false,\r\n        label: { type: String, minlength: 2, maxlength: 20, default: 'primary', required: true },\r\n        address: {\r\n            addressLine1: { type: String },\r\n            addressLine2: { type: String },\r\n            city: { type: String },\r\n            region: { type: String },\r\n            country: { type: String },\r\n            zipCode: { type: String }\r\n        }\r\n    }],\r\n    websites: [{\r\n        _id: false,\r\n        label: { type: String, minlength: 2, maxlength: 20, default: 'primary', required: true },\r\n        url: { type: String, validate: Validators.urlValidator, required: true }\r\n    }],\r\n    socialProfiles: [{\r\n        _id: false,\r\n        label: { type: String, minlength: 2, maxlength: 20, required: true },\r\n        url: { type: String, required: true }\r\n    }],\r\n    description: { type: String }\r\n\r\nWhen I looked at the documents in the collection I noticed that all new documents get created with the `__v` property set to `null` instead of `0`. Obviously this causes the error when mongoose tries to apply $inc to increase the version. So far I get it.\r\n\r\n**However I can't see  why mongoose does initialize the field with `null`!** Has this something to do with the way my subdocument arrays are defined? Or could it be that this model also uses the discrimination feature?\r\n\r\n**Update:** It seems to have something to do with the mongo version. When running the save call on a 3.0.7 the problem does not occur. On newer versions, 3.2.x however it gets initialized with null as described above.\r\n\r\nI am using mongoose version 4.6.0 by the way."}}
{"actor":{"display_login":"BenBestmann"}}