【发布时间】:2020-11-18 18:57:38
【问题描述】:
有没有办法“获取”子文档中文档字段的值? book_id 在主文档中,如何在这里获取它的值 '''
const ExtraElements_Schema = new Schema({
label : {type : String, requires : true},
page : {type : Number},
id_resource : {type : Number, required : true},
description : {type : String}
},{toJSON : {virtuals : true , getters : true}})
ExtraElements_Schema.virtual('path').get(function(){
const host = global.gConfig.thisServerHost;
return `${host}/${this.book_id???}/${this.id_resource}`
})
const Extra_Schema = new Schema({
label : {type : String, required : true},
book_id : {type : Number},
id_extra : {type : Number, required : true},
extras : [ExtraElements_Schema]
})
【问题讨论】:
标签: node.js express mongoose mongoose-schema