基本约束:
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 queriesvalidate
: 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限定最大日期