猫鼬最多不能工作 3 级



>我正在尝试填充嵌套在我的模型中的字段,但它没有填充。

这是我模型中的一个字段。

pendingChanges: {
credentials: {
university: {
name: { type: String },
major: { type: String },
majorGpa: { type: Number },
},
school: {
name: { type: String },
degreeType: { type: String },
degree: { type: String },
},
subjects: [{ type: mongoose.Schema.Types.ObjectId, ref: 'subject' }],
workExperience: {
type: { type: String },
from: { type: Date },
to: { type: Date },
},
},
},

我正在尝试填充嵌套在其中的主题键。

这就是我到目前为止所做的。

const teacher = (await this.findById(id))
.populate({
path: 'pendingChanges',
populate: {
path: 'credentials',
populate: {
path: 'subjects',
},
},
});

我找到了解决方案。这是我为使其工作所做的。

const data = await this.findOne(query)
.populate({
path: 'pendingChanges.credentials.subjects',
});

最新更新