Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
Populate a document nested inside an array nested inside a model, mongoose

I have the following model where I store a reference to a another document inside an array of another model:

const ProgramExecutionSchema = new Schema({
  user: { type: Schema.Types.ObjectId, ref: "User", required: true },

  executions: [
    {
      programId: {
        type: Schema.Types.ObjectId,
        ref: "Program.program",
        required: true,
      },

      date: { type: Date, required: true },

      executionRate: { type: Number, required: true, min: 0, max: 100 },

      grade: { type: Number, required: true, default: 0, min: 0, max: 10 },
    },
  ],
});

and this is the model it refers to (I want to populate a specific program inside the program array) :

const ProgramSchema = new Schema({
  user: { type: Schema.Types.ObjectId, ref: "User", required: true },

  program: [
    {
      day: {
        type: String,
        required: true,
        enum: [
          "Sunday",
          "Monday",
          "Tuesday",
          "Wednesday",
          "Thursday",
          "Friday",
          "Saturday",
        ],
      },

      restDay: { type: Boolean },

      workout: { type: Schema.Types.ObjectId, ref: "Workout" },
    },
  ],
});

When trying to populate the 'programId' field it just ignores it. But the _id that I store inside 'ProgramExecution' model is correct. So I am not sure if I am using the right query for population. here is what I tried:

const programExecutions = await ProgramExecution.findOne({
    user: userId,
  }).populate({
    path: 'executions',
    populate: {
      path: 'programId',
      model: 'Program',
    },
  });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!