我有两个收藏:
//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'}
但没有任何效果。
有任何想法吗?