I have a circuit like this:
var testSchema = new Schema({
foo: { type: String, required: true, trim: true },
bar: {
fooBar: { type: String },
barFoo: { type: String }
}
});
And I have to check the values barbased on the values foo, something like this:
testSchema.path("bar").validate(function(bar){
if(this.foo === "someValue")
else if(this.foo === "anotherString")
else
return false;
});
But when I try to strat my application, I get the following error:
/Users/Renato/github/local/prv/domain/models/testModel.js:34
testSchema.path("bar").validate(function(bar){
^
TypeError: Cannot call method 'validate' of undefined
What am I doing wrong here? What is the correct way to validate this object ??? I was looking for her, but I could not find anything! Even updated my mongoose version to~3.5.5
source
share