title: Mongoose nested/deep populate
body: <p>I know this question has been asked a lot of times but I'm kind of new to mongodb/mongoose! Currently I am working on a MEAN stack for a medical software. The following is my schema:</p>
  
  <pre><code>var usersSchema = new Schema({
      _id      : {type : mongoose.Schema.ObjectId}
    //...
  });
  mongoose.model('Users', usersSchema);
  
  var doctorsSchema = new Schema({
      _id      : {type : mongoose.Schema.ObjectId},
      userid      : {type : mongoose.Schema.ObjectId, ref : 'Users' },
    //...
  });
  mongoose.model('Doctors', doctorsSchema);
  
  var appointmentsSchema = new Schema({
    _id      : {type : mongoose.Schema.ObjectId},
    doctorids       : [ {type : mongoose.Schema.ObjectId, ref : 'Doctors'} ]
    //...
  });
  mongoose.model('Appointments', appointmentsSchema);
  </code></pre>
  
  <p><strong>Nested Mongoose Populate</strong>: How do I implement a nested mongoose populate on Appointments.find() in a way that  Appointments.find().populate('doctorids') should populate the array of Doctors and the array of Doctors in turn should populate the Users each Doctor points to. As per <a href="https://github.com/LearnBoost/mongoose/wiki/3.6-Release-Notes#population" rel="nofollow noreferrer">https://github.com/LearnBoost/mongoose/wiki/3.6-Release-Notes#population</a> they added Model.Populate! So I tried this but its NOT populating the Users inside the doctorids</p>
  
  <p>&nbsp;</p>
  
  <pre><code>Appointments
    .find({})
    .populate('doctorids')  // This is working
    .exec(function (err, doc) {
      if (err) {
        handleError(err);
        return;
      }
      Doctors //**Shouldn't this populate the doctors Users inside Doctors?**
        .populate(doc, {path: 'doctorids.userid'}, function(err, doc) {       
      }); 
      res.json({
        appointments: doc //Appointsments.Doctorids[].Userid is NOT populated
      });
  });  
  </code></pre>
  
  <p>[Edited: Moved the other questions to a new post @ <a href="https://stackoverflow.com/questions/27412928/mongoose-nested-populate-sort-search-referenced-attributes">https://stackoverflow.com/questions/27412928/mongoose-nested-populate-sort-search-referenced-attributes</a> ]</p>