我有团队的以下模型
从数据库中获取数据时,我可以填充主管,但不能填充指挥员数组中的员工var team = new mongoose.Schema({ supervisor: { type: mongoose.Schema.Types.ObjectId, ref: 'employee' }, // SupervisorId commanders: [{ employee: { type: mongoose.Schema.Types.ObjectId, ref: 'employee' }, //under supervisor level: { type: Number, defult: 1 } }] });
我尝试了类似下面的内容
db.team.findOne({ supervisor: employeeId }).populate({ path: 'supervisor', populate: { path: 'commanders', populate: { path: 'employee', model } } })
需要帮助。!!
答案 0 :(得分:1)
试试这个:
db.team.findOne({
supervisor: employeeId
}).populate('supervisor commanders.employee')