設置vitual屬性
personSchema.virtual('name.full').get(function () { return this.name.first + ' ' + this.name.last; });
獲取vitual屬性,兩種方式獲取:
1.doc._doc.full
獲取
2.doc.toObject({virtuals: true}
) 格式化后獲取
設置vitual屬性
personSchema.virtual('name.full').get(function () { return this.name.first + ' ' + this.name.last; });
獲取vitual屬性,兩種方式獲取:
1.doc._doc.full
獲取
2.doc.toObject({virtuals: true}
) 格式化后獲取
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。