1

I Have following model for a team

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 }
    }]
});

while fetching data from DB I am able to populate supervisor but not employees in commanders array

I tried something like below

db.team.findOne({
        supervisor: employeeId
    }).populate({
        path: 'supervisor',
        populate: {
            path: 'commanders',
            populate: {
                path: 'employee',
                model
            }
        }
    })

Need help.!!

1 Answer 1

1

Try with This:

db.team.findOne({
       supervisor: employeeId
   }).populate('supervisor commanders.employee')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.