我有两个系列:
//col1
var schema1 = new mongoose.Schema({
_id: ... ,
name1: String,
objects1: [{
_id: ... , <-- reference to this !!!!!!!!!!!!!!
obj_name: String
}]
});
//col2
var schema2 = new mongoose.Schema({
_id: ... ,
name2 : String,
objects2 : [{
_id: ... ,
_source: {type: mongoose.Schema.ObjectId, ref: 'col1'}
}]
});
如果我做的话
schema.statics.getByName = function(name, callback) {
mongoose.model('col2').findOne({ name2 : name }).populate('objects2').exec(callback);
};
返回对象未填充。
我非常确定问题是,我所引用的对象存储在一个数组中,并且它不是文档ID。
我尝试通过_source: {type: mongoose.Schema.ObjectId, ref: 'col1.objects1'}
来解决这个问题,但没有任何影响。
有什么想法吗?