SchemaType Options验证功能

  • 加入验证的目的就是为了统一数据库中的数据的完整一致性

基本约束:

  • required: boolean or function, if true adds a required validator for this property

    • 必须约束

  • default: Any or function, sets a default value for the path. If the value is a function, the return value of the function is used as the default.

    • 默认约束

  • select: boolean, specifies default projections for queries

  • validate: function, adds a validator function for this property

    • 自定义约束条件

  • get: function, defines a custom getter for this property using Object.defineProperty().

    • 数据属性的 get 约束

    • 当你访问该属性的时候会自动调用 get 方法

  • set: function, defines a custom setter for this property using Object.defineProperty().

    • 数据属性的 set 约束

    • 当你为数据属性赋值的时候会自动调用 set 方法

索引(暂时还不需要考虑):

  • index: boolean, whether to define an on this property.

  • unique: boolean, whether to define a unique index on this property.

  • sparse: boolean, whether to define a sparse index on this property.

字符串:

  • lowercase: boolean, whether to always call .toLowerCase() on the value

    • 自动转为小写

  • uppercase: boolean, whether to always call .toUpperCase() on the value

    • 自动转为大写

  • trim: boolean, whether to always call .trim() on the value

    • 自动去除空格

  • match: RegExp, creates a validator that checks if the value matches the given regular expression

    • 自定义字符串的验证规则

  • enum: Array, creates a validator that checks if the value is in the given array.

    • 枚举类型,必须是数组中指定的某个枚举元素

数字:

  • min: Number, creates a validator that checks if the value is greater than or equal to the given minimum.

    • 限定最小数字

  • max: Number, creates a validator that checks if the value is less than or equal to the given maximum.

    • 限定最大数字

日期:

  • min: Date

    • 限定最小日期

  • max: Date

    • 限定最大日期

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值