2015-05-28 48 views
0

当我试图保存在数据库中的数据,它给禁消息猫鼬验证给“CastError:铸铁未定义的失败值”

CastError:铸铁未定义的失败值

[ 
    {"product":{"supplierId":{"undefined":"rfytr"}}}, 
    {"product":{"supplierId":{"$empty":"rfytr"}}} 
] at path "condition" 

我无法弄清楚问题所在。 我的架构是

var mongoose = require('mongoose'), 
    validator = require('mongoose-validators'), 
    Schema = mongoose.Schema; 
var RuleSchema = new Schema({ 
    description: { 
     type: String, 
     validate: [validator.isLength(1, 50)] 
    }, 

    status: { 
     type: String, 
     enum: ['live', 'active', 'paused', 'inactive', 'unfinished'] 
    }, 

    /** 
     condition. It can only contain object. 
    */ 
    condition: [{ 
     type: Object 
    }] 
}); 

回答

1

我无法重现,准确的错误,但你应该改变你的架构condition的定义是一种支持的格式的非结构化对象的数组,因为我是越来越其他错误尝试使用[{type: Object}]。这两种工作:

condition: [{}] 
condition: [Schema.Types.Mixed] 

但你还需要在$empty字段名称去除导致$作为一个$aren't allowed通过MongoDB的开始字段名。