1

So, I have 3 schemas,

User

const UserSchema = new mongoose.Schema({
    ...,    
    weekly: [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Weekly'
    }]
});

Weekly

const weeklyAnalyticSchema = new mongoose.Schema({      
  daily: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'DailyAnalytic'
  }],
  weekStart: {
    type: Date,
    // default: addDaystoDate(1)
  },
  weekEnd: {
    type: Date,
    // default: addDaystoDate(7)
  }
})

Daily

const Daily = new mongoose.Schema({
  date: Date,
  foo: bar
})

I'm trying to populate the daily array inside the weekly array, like so...

I do this, following the documentation from mongoosejs mongoose deep populate

let found = await db.User.findById(req.user._id).populate({
path: "weeklyAnalytics",
populate: {
  path: "dailyAnalytics"
}).exec()

and it comes out like this

 daily: [ 1],
  weekly: [
    {
      daily: [Array],
      _id: 1,                   
      __v: 0
    }
  ],

i've tried many others as well and read and modified other peoples code, but I can't seem to get that daily inside the weekly to populate.

1 Answer 1

1

why does the answer always come up to the questioner after he asks the question

i just have to do console.log(found.week) and everything will show up.

now I can do whatever.

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.