我只是在app.js文件中执行以下操作:
var mongoose = require('mongoose');mongoose.connect('mongodb://address_to_host:port/db_name');modelSchema = require('./models/yourmodelname').YourModelName;mongoose.model('YourModelName', modelSchema);// TODO: write the mongoose.model(...) command for any other models you have.此时,任何需要访问该模型的文件都可以执行以下操作:
var mongoose = require('mongoose');YourModelName = mongoose.model('YourModelName');最后,在模型中,可以正常编写文件,然后将其导出到底部:
module.exports.YourModelName = YourModelName;
我不知道这是否是最好的最棒的解决方案(大约两天前才开始将我的头缠在导出模块上),但是它确实有效。也许有人可以发表评论,如果这是个好方法。



