Node.js:如何获取错误对象中的不正确的字段

我在下面的架构中有独特和必填字段。

当其中的任何一个留空时,将返回一个错误。

如何在Error对象中find有关哪些字段留空的信息?

 var mongoose = require('mongoose'); var uniqueValidator = require('mongoose-unique-validator'); var Schema = mongoose.Schema; var kullaniciShema = new Schema({ gsm: String, email: String, kullaniciAdi: { type: String, required: true, unique: true }, sifre: { type: String, required: true}, }, { collection: 'kullanici' }); kullaniciShema.plugin(uniqueValidator); var Kullanici = mongoose.model('Kullanici', kullaniciShema); module.exports = Kullanici; 

下面是我提交的数据保存到数据库的控制器。 一些传入的数据是空的,所以我得到一个空白字段的错误。

如何在Error对象中find不正确的字段?

 var yeniKullanici = new Kullanici({ gsm: req.body.gsm, email: req.body.email, kullaniciAdi: req.body.kullaniciAdi, sifre: req.body.sifre, }); yeniKullanici.save(function(err){ if (err) { //var error=new err("hata"); //console.log(error.path); selectAllFromKullanici((result) => { //console.log(forUsersError.length); forUsersError[forUsersError.length] = assert.equal(error.errors['ad'].message, 'Path `name` is required.'); res.render("kullanicilar", { kullanicilar: result, hata: forUsersError }); }) } else { selectAllFromKullanici((result) => { res.render("kullanicilar", { kullanicilar: result }); }) } }); 

我很抱歉我的英语不好。

我会检查,如果这些字段是空的,然后再尝试运行到一个失败,并从错误消息中提取数据,这可能会失败,未知的错误。