【发布时间】:2013-02-03 16:17:35
【问题描述】:
我一直在尝试关注Mongoose Population 中的信息,但我遇到了异常:
MissingSchemaError:尚未为模型“未定义”注册架构。
我的代码是这样的:
mongoose = require('mongoose');
Schema = mongoose.Schema;
mongoose.connect(MONGO_SERVER);
ObjectId = Schema.ObjectId;
var FirstSchema = new Schema({
label : String
});
var SecondSchema = new Schema({
first_id : [{ type: mongoose.Schema.ObjectId, ref: 'First' }],
type : String,
...
});
var first= mongoose.model('First', FirstSchema);
var second= mongoose.model('Second', SecondSchema);
function test() {
...
second.find({}).populate('first_id').exec(function(err,data){return true;});
...
}
错误发生在填充上,我已经根据论坛上的不同答案对其进行了多次调整,我相信这会很简单,但有人能指出我正确的方向吗?
干杯。
【问题讨论】: