Mongoose expand default validation

后端 未结 4 530
天涯浪人
天涯浪人 2021-01-06 17:49

I want to build \"minLength\" and \"maxLength\" in the mongoose schema validation rules, the current solution is:

var blogSchema = new Schema({
  title: { re         


        
4条回答
  •  粉色の甜心
    2021-01-06 18:08

    maxlength and minlength now exist. You code should work as follows.

        var mongoose = require('mongoose');
        var blogSchema = new mongoose.Schema({
            title: {
                 type: String,
                 required: true,
                 minLength: 8,
                 maxLength: 32
            }
        });
    

提交回复
热议问题