猫鼬: - 如何填充另一个人口?

时间:2016-02-19 13:20:33

标签: mongodb mongoose populate

学生

{ "_id" : ObjectId("56c0788bace9035672a9763b"), 
  "firstName" : "John", 
  "lastName" : "Jackson",
  "dob" : null, 
  "contact" : ObjectId("56c0788aace9035672a97639"), 
  "confirm" : false, 
  "badRecord" : false, 
  "createdAt" : ISODate("2016-02-14T12:52:27.076Z"), 
  "enrolments" : [ ObjectId("56c0788aace9035672a9763a"), ObjectId("56c0d62ee0c111267d7eb4d2") ], 
  "__v" : 0 
}

注册

{ "_id" : ObjectId("56c0788aace9035672a9763a"), 
  "confirm" : true, 
  "tuition" : ObjectId("56bf79ee15e2bb615fa0e264"), 
  "createdAt" : ISODate("2016-02-14T12:52:2

学费

{ "_id" : ObjectId("56bf79ee15e2bb615fa0e264"), 
 "subject" : ObjectId("56bf799b15e2bb615fa0e260"), 
 "grade" : ObjectId("56bf79a515e2bb615fa0e261"), 
 "startDate" : ISODate("2016-02-26T00:00:00Z"), 
 "endDate" : ISODate("2016-04-28T00:00:00Z"), 
  "classTime" : 480, 
  "teacherName" : ObjectId("56bf79be15e2bb615fa0e263"),
  "totalSeats" : 30, 
  "seatsAvailable" : 24, 
  "tuitionFee" : 0, 
  "publish" : true, 
  "extraString" : "", 
  "createdAt" : ISODate("2016-02-13T18:46:06.305Z"), "__v" : 0 }

查询

 model.Student.find()
       .populate('contact')
       .populate( {path:'enrolments',
            populate:{path:'tuition', 
                      model:'Tuition', 
                      populate:{path:'subject', model:'Subject' }} }).
            sort({'createdBy':-1}).sort({'firstName':1}).exec(function(err,data){
}

我可以填充学费模型中的学科数据,学费模型在招生中。

我想知道在上述案例中有没有办法填充学费中的所有模型

0 个答案:

没有答案