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