这是我的架构:
var sourcesSchema = {
title: String,
name: String,
url: String,
description: String,
category: Array,
rating: Number,
source_pages: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'source_page',
}]
}
var sourcePageschema = {
uname: String,
source_name: String,
page_address: String,
driver_name: String,
product: {
type: mongoose.Schema.Types.ObjectId,
ref: 'products' //Edit: I'd put the schema. Silly me.
}
}
var productsSchema = {
title: String,
uname: String,
descriptin: String,
images: Array,
currency: String,
last_update_time: Number,
last_process_time: Number,
meta_data: {},
tags: Array,
min_price: Number,
max_price: Number,
prices: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'prices' //Edit: I'd put the schema. Silly me.
}]
}
此代码有效并成功填充 source_pages :
_sources.find().populate('source_pages').exec(function (err,sources) {
res.json(200, sources);
});
但如果我也想填充产品:
_sources.find().populate('source_pages').populate('source_pages.product').exec(function (err,sources) {
res.json(200, sources);
})
这个错误:
TypeError:无法在搜索时调用未定义的方法“路径”(/home/sina/rhino2/node_modules/mongoose/lib/model.js:2088:28)在搜索(/home/sina/rhino2/node_modules/mongoose/lib/ model.js:2107:22) 在 Function._getSchema (/home/sina/rhino2/node_modules/mongoose/lib/model.js:2114:5) 在填充 (/home/sina/rhino2/node_modules/mongoose/lib/ model.js:1719:22) 在 Function.Model.populate (/home/sina/rhino2/node_modules/mongoose/lib/model.js:1702:5) 在 cb (/home/sina/rhino2/node_modules/mongoose/ lib/query.js:1690:11) 在 /home/sina/rhino2/node_modules/mongoose/lib/utils.js:414:16 在 /home/sina/rhino2/node_modules/mongoose/node_modules/mongodb/lib/mongodb /cursor.js:158:16 在 commandHandler (/home/sina/rhino2/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:643:16) 处为空。(/home/sina/rhino2/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1641:20)