下面是makerSchema
var makerSchema = new mongoose.Schema({
materials:[{
material:{
type: String,
required:[true, "Material is a required field"],
trim:true,
lowercase:true,
enum:{
values:['wood','metal','plastic','glass','concrete','other'],
message: 'Please choose from the given options only!'
}
}
}]
},{
timestamps:true
})
var Maker = mongoose.model('Maker', makerSchema);
我通过POST路由传递了以下数据,但收到错误
{
"materials":["glass"]
}
我收到以下错误
ValidationError: materials: Cast to Array failed for value "[ 'glass' ]" at path "materials"
如何解决此错误并通过数组?
{ material: 'some string' }
为什么会出错