schema
来源:互联网 发布:java的sleep 编辑:程序博客网 时间:2024/04/30 05:27
对于mongodb数据库,由于在数据映射时,事先定义好的字段可能后期需要添加。这时若直接在schema类内直接定义,是不行的。这时就需要用到.add方法作为后期添加字段。
schema.add({ avatar : 'img.png'});
schema的prototype属性方法。
schema.eachPath//similar to Array forEachschema.get(key)schema.index({ first: 1, last: -1 })//创建索引。schema.loadClass(model)// 引入es6 的关键字
virtuals
Note that if the resulting record is converted to an object or JSON, virtuals are not included by default. Pass virtuals : true to either toObject() or to toJSON() to have them returned.
用于数据库查询出的对象是一个自定义的json或object,由于不是mongoose支持的数据类型,所以要设置virtuals.
{ strict: true, toObject: { virtuals: true }, toJSON: { virtuals: true } } UserSchema.virtual('isAdvanced').get(function () { // 积分高于 700 则认为是高级用户 return this.score > 700 || this.is_star;});
0 0
- Schema
- schema
- Schema
- schema
- Schema
- Schema
- Schema
- Schema
- Schema
- schema
- Schema
- Schema
- Schema
- Schema
- Schema
- schema
- schema
- schema
- TIMESTAMP with implicit DEFAULT value is deprecated
- javascript时间和日期,实现时钟功能之浅析
- jsp的9个内置对象
- nginx 虚拟域名映射
- VS编辑后期生成事件
- schema
- 四大域对象
- Cookie的作用域
- 从绩效管理到价值管理,从资源共享到资源创新
- onvif云台巡航控制
- tyoj 1059 过河【压缩】
- Unable to instantiate Action, XXXAction, defined for 'xx' in namespace 'xx'报错解决
- JAVA连接mysql数据库例程
- 区间筛