节点jS Express Mongoose模式验证无法正常工作

我在mongoose节点js包中遇到问题。在我的快速设置中,我的函数内有这段代码

    const SomeModelSchema = new Schema({
      test: {
          type: String,min:[6,'min length should be 6'],required: true
      },sirname: {
          type: Number,min: [3,'min 3 length'],required: true,}      
  });

  var SomeModel = mongoose.model('SomeModel',SomeModelSchema );

  var somemodel = new SomeModel({
      test:'aj',sirname: '1234'    });

    var error=somemodel.validateSync()

    if(error){
      console.log(error);
    }
    console.log(error);
    return somemodel.save()  

test上至少6分钟的验证不起作用,而是对键sirname起作用。

hliyouheng 回答:节点jS Express Mongoose模式验证无法正常工作

min验证程序用于数字,对于字符串,则需要使用minlength

更多信息:here

本文链接:https://www.f2er.com/3022998.html

大家都在问