1
做嵌套填入
我的類模式是:我得到「類型錯誤:無法調用‘’未定義」路徑,而在貓鼬
var CategorySchema = new Schema({
subcategories:[{type : Schema.ObjectId, ref : 'Category', null: true}],
parent: {type : Schema.ObjectId, ref : 'Category', null: true},
products:[{type : Schema.ObjectId, ref : 'Product'}]
})
當我試圖讓嵌套填充像下面,我正在「不能調用未定義」
list: function (options, cb) {
var criteria = options.criteria || {}
, Category = this
this.find(criteria)
.populate('subcategories')
.exec(function(err,docs){
if(err){
console.log(err.message);
cb(err);
}
var opts = [
{ path: 'subcategories.products' }
];
Category.populate(docs, opts, function(err, docs2) {
if(err){
cb(err);
}
cb(docs2);
})
})
}
我在哪裏錯了方法 '路徑'?