0

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://github.com/LearnBoost/mongoose.git" and doing npm install but it still happens.

let me know if you need more info

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I Don't understand. I can't have normal mongoose modelless objects in my array?
Your mongoose models must conform to a schema. You can use [mongoose.Schema.Types.Mixed] if you want to allow heterogeneous object types in your array, but if your schema declares that the array contains other models like [SomeOtherSchema], then mongoose expects only SomeOtherModel instances in that array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.