【发布时间】:2015-02-08 00:04:12
【问题描述】:
我一直在尝试使用 mongolab 作为我的 mongodb 在heroku 上部署我的sails 应用程序。
我使用了以下连接,一个用于开发,一个用于生产:
local_mongo : {
adapter : 'sails-mongo',
host : 'localhost',
port : 27017,
database : "something"
},
heroku_mongolab : {
adapter : "sails-mongo",
url : "mongodb://*****:******!@ds063160.mongolab.com:63160/something"
}
我还设置了我的 local.js 文件以使用开发环境并将该文件放在 gitignore 上。
最后在我的 development.js 上,我执行以下操作
module.exports = {
models: {
connection: 'local_mongo'
}
};
在我的 production.js 上
module.exports = {
/***************************************************************************
* Set the default database connection for models in the production *
* environment (see config/connections.js and config/models.js ) *
***************************************************************************/
models: {
connection: 'heroku_mongolab'
}
/***************************************************************************
* Set the port in the production environment to 80 *
***************************************************************************/
//port: 80
/***************************************************************************
* Set the log level in production environment to "silent" *
***************************************************************************/
//log: {
// level: "silent"
//}
};
在我的 package.json 上,我将启动脚本更改为 node app.js --prod。在本地运行时,即使我运行 npm start,一切都按预期运行,但是当我在 heroku 上部署并查看日志时,我发现它尝试连接到 localhost mongodb。
这是一个错误还是我做错了什么?
【问题讨论】: