我使用的RestMVC.js模块轮流使用Mongoose进行模型声明。比方说,我有一个模型声明了几个文件,其中一些使用这些类的成员变量ALA:RestMVC.js(Mongoose)&Node.JS - 外部模型文件
// Foo.js file
module.exports.Foo = function(mongoose)
{
var Schema = mongoose.Schema;
var Foo = mongoose.model('Foo', new Schema({
TestMember: String,
SecondTestMember: Date
}));
return mongoose.model('Foo');
};
// Bar.js file
module.exports.Bar = function(mongoose)
{
var Schema = mongoose.Schema;
var Bar = mongoose.model('Bar', new Schema({
DerivedMember: Foo,
Blah: String
}));
return mongoose.model('Bar');
};
什么是从其他参考一个模型的正确方法吗?我试图做require('models/Foo.js')和exports.Foo以及mongoose.exports.Foo无济于事。
一种方法是将预先加载的所有模式,但什么是存储和访问他们的最好的地方?我不想污染全球空间,也许是猫鼬。 –