mongoose的virtual属性

  设置vitual属性

personSchema.virtual('name.full').get(function () {
  return this.name.first + ' ' + this.name.last;
});
获取vitual属性,两种方式获取:

1.doc._doc.full获取

2.doc.toObject({virtuals: true}) 格式化后获取

 

posted @ 2017-01-16 16:21  jay-  阅读(3017)  评论(0编辑  收藏  举报