这里我有2个架构:
用户:
User = {
name: String,
office: {
type: mongoose.Schema.ObjectId,
ref: 'Office'
}
}
办公室:
Office = {
name: String
}
Office.virtual('employees', {
ref: 'User',
localField: '_id',
foreignField: 'office',
justOne: false
});
当我尝试更新Office.employees时,我无法通过引用更新User.office,我该怎么做?
为了更新我使用:
Office.findByIdAndUpdate(id, {employees: ['id of employee']})