Mongoose For Node.js error object has no method validate


I Am making a blog with node/express/mongoose and I keep getting this error:

/Users/Ari/Sites/Amateur Dev/node_modules/mongoose/lib/schema/documentarray.js:94 doc.validate(function (err) { ^ TypeError: Object # has no method 'validate' at DocumentArray.doValidate (/Users/Ari/Sites/Amateur Dev/node_modules/mongoose/lib/schema/documentarray.js:94:13) at DocumentArray.doValidate (/Users/Ari/Sites/Amateur Dev/node_modules/mongoose/lib/schema/documentarray.js:102:9) at DocumentArray.SchemaType.doValidate (/Users/Ari/Sites/Amateur Dev/node_modules/mongoose/lib/schematype.js:601:22) at DocumentArray.doValidate (/Users/Ari/Sites/Amateur Dev/node_modules/mongoose/lib/schema/documentarray.js:73:35) at Document.validate.err (/Users/Ari/Sites/Amateur Dev/node_modules/mongoose/lib/document.js:911:9) at process.startup.processNextTick.process._tickCallback (node.js:244:9)

I have tried uninstalling mongoose changing my package.json with "mongoose": "git://" and doing npm install but it still happens.

let me know if you need more info

Problem courtesy of: Ari Porad


First guess is your schema defines an array of subdocuments, and mongoose expects that array to always contain only mongoose model instances, but your code is putting something else in there, probably some plain javascript objects instead of mongoose model instances, which contain an _doc property that represents the underlying mongodb document.

You just need to put "mongoose": "3.5.x" in your package.json, not the full URL.

Solution courtesy of: Peter Lyons


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.