MongoDB关联查询
Last updated
Was this helpful?
Last updated
Was this helpful?
当设计数据表,需要往数据表中添加新的列的时候,只需要更改集合中的Schema模型,然后对原来的信息进行挨个的修改
1.首先来说说这个Schema的设计的问题
在数据类型上就分为以下几种
所有数据类型都有的选项,还有一些只有某些数据类型才有的选项,具体可参考官方网址
required
: boolean or function, if true adds a 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 for queries
validate
: function, adds a for this property
get
: function, defines a custom getter for this property using .
set
: function, defines a custom setter for this property using .
alias
: string, mongoose >= 4.10.0 only. Defines a with the given name that gets/sets this path.
在这个数据类型设计的时候我犯了两个错误
1.required少打了,打成require
2.default生效的情况是在初始化一个实例对象的时候就没有,申明position字段才会将默认值填充到数据之中
2.多表进行关联查询
参考