Search code examples
mongoose-schemamongoose-populate

populate Mongoose subdocument


I have an issue regarding a mongoose schema :

`var ProjectSchema = new mongoose.Schema({
    name: String,
    resources: [{
        employee: {type: Schema.Types.ObjectId, ref: 'Employee'},
        dailyRate: Number
    }],`...

and I'm trying with no success to populate the resources.employee field... already tried :

  • .populate('resources.employee')
  • .populate('resources.employee', model: 'Employee'})
  • etc ...

any advice ?

Thanks in advance


Solution

  • nevermind, was just my insert that did not work...

    the correct syntax is :

    .populate({path:'resources.employee', model:'Employee'})