【发布时间】:2016-04-23 05:25:47
【问题描述】:
我有以下三种型号:
var User = {
first_name: String,
last_name: String,
}
var Student = {
role = String,
user = {type: mongoose.Schema.Types.ObjectId, ref: 'User'}
groups = [{type: mongoose.Schema.Types.ObjectId, ref: 'Group'}],
}
var Group = {
name = String,
students = [{type: mongoose.Schema.Types.ObjectId, ref: 'Student'}],
}
我的快速获取方法如下:
router.route('/')
.get(function(req, res){
Group.find().populate('students').exec(function(err, groups){
res.json(groups);
});
我的 json 对象返回填充的学生对象数组,但我只从每个学生对象中接收一个 user._id。我怎样才能让用户对象填充?任何信息都会很棒!谢谢
【问题讨论】:
-
为什么在 Student 和 Group 对象中的键和值用“=”而不是“:”分开?
-
我的错误,只是一个错字。我在实际模型中使用了冒号:)
标签: javascript mongodb express mongoose mean-stack