我有这样的架构:
var testSchema = new Schema({
        foo: { type: String, required: true, trim: true },
        bar: {
            fooBar: { type: String },
            barFoo: { type: String }
        }
});
而且我必须验证bar基于值的foo值,如下所示:
testSchema.path("bar").validate(function(bar){
    if(this.foo === "someValue")
        //return custom validation logic 1
    else if(this.foo === "anotherString")
        //return custom validation logic 2  
    else
        return false;
});
但是当我尝试对我的应用进行分层时,我收到以下错误:
/Users/Renato/github/local/prv/domain/models/testModel.js:34
testSchema.path("bar").validate(function(bar){
                       ^
TypeError: Cannot call method 'validate' of undefined
我在这里做错了什么?验证此对象的正确方法是什么???我用谷歌搜索了它,但我似乎找不到任何东西!甚至将我的猫鼬版本更新为~3.5.5