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}) 格式化后获取

 

原文地址:https://www.cnblogs.com/jay--zhang/p/6290105.html