【发布时间】:2020-05-23 20:24:24
【问题描述】:
我有一个模式,其中一个字段被标记为必填,我有许多记录要插入到 db 但一条记录没有标记为必填的字段,但我也想插入该记录而不输入数据到按要求标记的文件。有没有可能我可以以这种方式插入数据库。我如何通过提供所需的错误字段来管理该记录。
fi
e
ld2: {
type: String,
required: function() {
if(this.field2) { return true }
else return false
}
}
//trying to insert the data from controller
//some code..
let jsonData ={field2 :"",field2 :'abcd'}
var test = new SchemaTest()//creating schema instance
for(var i in jsonData)
//for below code for first iteration field2 have no data,
//second have data
test.field2 = jsonData.field2
test.save((err,test)=> {})
【问题讨论】: