{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3816","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3816/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3816/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3816/events","html_url":"https://github.com/Automattic/mongoose/issues/3816","id":129487515,"number":3816,"title":"doc.validate is not a function","user":{"login":"raistlinthewiz","id":73215,"avatar_url":"https://avatars.githubusercontent.com/u/73215?v=3","gravatar_id":"","url":"https://api.github.com/users/raistlinthewiz","html_url":"https://github.com/raistlinthewiz","followers_url":"https://api.github.com/users/raistlinthewiz/followers","following_url":"https://api.github.com/users/raistlinthewiz/following{/other_user}","gists_url":"https://api.github.com/users/raistlinthewiz/gists{/gist_id}","starred_url":"https://api.github.com/users/raistlinthewiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raistlinthewiz/subscriptions","organizations_url":"https://api.github.com/users/raistlinthewiz/orgs","repos_url":"https://api.github.com/users/raistlinthewiz/repos","events_url":"https://api.github.com/users/raistlinthewiz/events{/privacy}","received_events_url":"https://api.github.com/users/raistlinthewiz/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":null,"comments":4,"created_at":"2016-01-28T15:42:25Z","updated_at":"2016-03-03T00:35:59Z","closed_at":"2016-02-22T17:13:17Z","body":"```\r\nnode_modules\\mongoose\\lib\\schema\\documentarray.js:104\r\n      doc.validate({ __noPromise: true }, function(err) {\r\n          ^\r\n\r\n  TypeError: doc.validate is not a function\r\n\r\n  - documentarray.js:104\r\n    [hypetrain]/[mongoose]/lib/schema/documentarray.js:104:11\r\n\r\n  - schematype.js:654 DocumentArray.SchemaType.doValidate\r\n    [hypetrain]/[mongoose]/lib/schematype.js:654:22\r\n\r\n  - documentarray.js:77 DocumentArray.doValidate\r\n    [hypetrain]/[mongoose]/lib/schema/documentarray.js:77:35\r\n\r\n  - document.js:1171\r\n    [hypetrain]/[mongoose]/lib/document.js:1171:9\r\n\r\n  - node.js:433 nextTickCallbackWith0Args\r\n    node.js:433:9\r\n\r\n  - node.js:362 process._tickCallback\r\n    node.js:362:13\r\n```\r\n\r\nmy schema;\r\n\r\n```\r\nvar GameStatisticsSchema = new mongoose.Schema({\r\n    game: { type: mongoose.Schema.ObjectId, ref: 'Game', required: true }, // associated game subverse.\r\n    months: [\r\n      { // monthly viewers\r\n          epoch: { type: Number, required: true }, // entry time stamp\r\n          weeks: [\r\n            { // weekly viewers\r\n                epoch: { type: Number, required: true }, // entry time stamp\r\n                days: [\r\n                  { // daily viewers\r\n                      epoch: { type: Number, required: true }, // entry time stamp\r\n                      hours: [\r\n                        { // hourly viewers\r\n                          epoch: { type: Number, required: true }, // entry time stamp\r\n                          minutes: [\r\n                            { // per minute statistics.\r\n                                viewers: { type: Number },\r\n                                channels: { type: Number },\r\n                            }]\r\n                      }]\r\n                }]\r\n          }]\r\n    }]\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/191508825","html_url":"https://github.com/Automattic/mongoose/issues/3816#issuecomment-191508825","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3816","id":191508825,"user":{"login":"syuilo","id":4439005,"avatar_url":"https://avatars.githubusercontent.com/u/4439005?v=3","gravatar_id":"","url":"https://api.github.com/users/syuilo","html_url":"https://github.com/syuilo","followers_url":"https://api.github.com/users/syuilo/followers","following_url":"https://api.github.com/users/syuilo/following{/other_user}","gists_url":"https://api.github.com/users/syuilo/gists{/gist_id}","starred_url":"https://api.github.com/users/syuilo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syuilo/subscriptions","organizations_url":"https://api.github.com/users/syuilo/orgs","repos_url":"https://api.github.com/users/syuilo/repos","events_url":"https://api.github.com/users/syuilo/events{/privacy}","received_events_url":"https://api.github.com/users/syuilo/received_events","type":"User","site_admin":false},"created_at":"2016-03-03T00:35:59Z","updated_at":"2016-03-03T00:35:59Z","body":"I have the same issue.\r\n\r\nMy schema definition:\r\n```\r\nimport {Schema, Connection, Document, Model} from 'mongoose';\r\n\r\n/* tslint:disable:variable-name */\r\n\r\nconst base: Object = {\r\n\tregisteredAt: { type: Date, required: true, default: Date.now },\r\n\tcreatedAt: { type: Date, required: false, default: null },\r\n\ttitle: { type: String, required: true },\r\n\tseries: [{ type: Schema.Types.ObjectId, required: false, default: null, ref: 'Series' }],\r\n\tcharacters: [{ type: Schema.Types.ObjectId, required: false, default: null, ref: 'Character' }],\r\n\ttags: [{ type: Schema.Types.ObjectId, required: false, default: null, ref: 'SSTag' }],\r\n\tisDeleted: { type: Boolean, required: false, default: false }\r\n};\r\n\r\nexport default function (db: Connection): Model<Document>[] {\r\n\tconst baseSchema = new Schema(Object.assign({\r\n\t\ttype: { type: String, required: true }\r\n\t}, base));\r\n\r\n\tconst threadSchema = new Schema(Object.assign({\r\n\t\turl: { type: String, required: true, unique: true },\r\n\t\ttype: { type: String, required: false, default: 'thread' },\r\n\t\tposts: [ new Schema({\r\n\t\t\tcreatedAt: { type: Date, required: true },\r\n\t\t\tnumber: { type: Number, required: true },\r\n\t\t\ttext: { type: String, required: true },\r\n\t\t\tuserName: { type: String, required: true },\r\n\t\t\tuserId: { type: String, required: true },\r\n\t\t\tisMaster: { type: Boolean, required: false, default: true }\r\n\t\t})]\r\n\t}, base));\r\n\r\n\tif (!(<any>baseSchema).options.toObject) {\r\n\t\t(<any>baseSchema).options.toObject = {};\r\n\t}\r\n\t(<any>baseSchema).options.toObject.transform = (doc: any, ret: any) => {\r\n\t\tret.id = doc.id;\r\n\t\tdelete ret._id;\r\n\t\tdelete ret.__v;\r\n\t};\r\n\r\n\tif (!(<any>threadSchema).options.toObject) {\r\n\t\t(<any>threadSchema).options.toObject = {};\r\n\t}\r\n\t(<any>threadSchema).options.toObject.transform = (doc: any, ret: any) => {\r\n\t\tret.id = doc.id;\r\n\t\tdelete ret._id;\r\n\t\tdelete ret.__v;\r\n\t};\r\n\r\n\tconst Base = db.model('SS', baseSchema, 'ss');\r\n\tconst Thread = db.model('SSThread', threadSchema, 'ss');\r\n\r\n\tconst init = Base.prototype.init;\r\n\tinit.thread = (<any>new Thread()).__proto__;\r\n\tBase.prototype.init = function (doc: any, fn: any): any {\r\n\t\tconst obj = init.apply(this, arguments);\r\n\t\tobj.__proto__ = init[doc.type];\r\n\t\treturn obj;\r\n\t};\r\n\r\n\treturn [\r\n\t\tBase,\r\n\t\tThread\r\n\t];\r\n}\r\n```\r\n\r\n```\r\nimport * as mongoose from 'mongoose';\r\nimport config from '../config';\r\n\r\n// Init mongo connection\r\nconst db = mongoose.createConnection(config.mongo.uri, config.mongo.options);\r\n\r\nimport ss from './schemas/ss';\r\n\r\nexport const SS = ss(db)[0];\r\n```\r\n\r\nMy code:\r\n```\r\nSS.findById('hoge', (err, ss) => {\r\n\tss.save();  // <- TypeError: doc.validate is not a function\r\n});\r\n```\r\n\r\nSorry my bad English. Thanks."}}