从父模式填充字段
Posted
技术标签:
????????????????????:populate field from parent schema ??????:2021-05-20 18:18:51 ??????:??????????:
const transactionSchema = mongoose.Schema(
amount: Number,
order:
type: mongoose.Schema.ObjectId,
ref: 'Order'
,
toJson: virtuals: true ,
toObject: virtuals: true
);
????Order Schema,???????(????????Order??)
const orderSchema = mongoose.Schema(
title: String,
driver:
type: mongoose.Schema.ObjectId,
ref: 'User'
)
????(??)???,????????????????? ????????:
const userSchema = new mongoose.Schema( ??:???,)
??????????? virtuals ??????
transactionSchema.virtual('driverName',
ref: 'User',
foreignField: 'name', //name of reference field in Review model
localField: 'driver' //name of reference in local Model
);
??????:
?????1?:???????????????(???????) ????docs
????:
以上是关于从父模式填充字段的主要内容,如果未能解决你的问题,请参考以下文章