我有以下型号:
LeaderSchema = new app.mongoose.Schema({
email: String,
projects: [{ type: app.mongoose.Schema.ObjectId, ref: 'Project'}]
});
ProjectSchema = new app.mongoose.Schema({
name: { type: String, required: true},
leader: { type: app.mongoose.Schema.ObjectId, ref: 'Leader'}
});
Leader = app.mongoose.model('Leader', LeaderSchema);
Project = app.mongoose.model('Project', ProjectSchema);
我想在我的控制器中做的是检索所有项目及其各自的领导者:
项目控制器.js:
module.exports = function(app) {
app.ProjectsController = {
index: function(req, res) {
app.Project.find(function(err, projects) {
res.send(projects)
})
}
}
}
但这只是给出了只有领导者 ID的项目列表
有没有办法让猫鼬热切地去找领导?