小编His*_*ija的帖子

如何在mongoose中加入两个集合

我有两个Schema定义如下:

var WorksnapsTimeEntry = BaseSchema.extend({
 student: {
     type: Schema.ObjectId,
     ref: 'Student'
 },
 timeEntries: {
     type: Object
 }
 });

var StudentSchema = BaseSchema.extend({
firstName: {
    type: String,
    trim: true,
    default: ''
    // validate: [validateLocalStrategyProperty, 'Please fill in your first name']
},
lastName: {
    type: String,
    trim: true,
    default: ''
    // validate: [validateLocalStrategyProperty, 'Please fill in your last name']
},
displayName: {
    type: String,
    trim: true
},
municipality: {
    type: String
    }
});
Run Code Online (Sandbox Code Playgroud)

我想循环通过每个学生并显示它的时间条目.到目前为止,我有这个代码,显然不对,因为我还不知道如何加入WorksnapTimeEntry模式表.

Student.find({ status: 'student' })
        .populate('student')
        .exec(function (err, students) …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js mongodb-query

8
推荐指数
3
解决办法
3万
查看次数

标签 统计

mongodb ×1

mongodb-query ×1

mongoose ×1

node.js ×1