Mongoose更新参考

时间:2018-02-02 10:21:41

标签: javascript node.js mongodb mongoose

这里我有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']})

0 个答案:

没有答案