What is the correct way to set a db connection in Sails v.0.10.x for production use? I expected Sails to use the connection I referred to in production.js when I start my app in production mode (environment), but it doesn't. It seems to always always use the default connection - 'localDiskDb'.
However, when I start sails in development mode (environment), it does use the connection specified in config/development.js, as I would have expected.
UPDATED
Note: I was mistaken when I wrote the location of production.js. It was in /config/env/production.js just like sgress454 said it should be. Actually, this file was created by the generator and put in the right place and I didn't change that.
config/env/production.js looks like this:
// config/env/production.js
module.exports = {
connection: 'mongo_production'
};
config/models.js looks like this:
// config/models.js
module.exports.models = {
// connection: 'localDiskDb'
};
config/connections.js looks like this:
// config/connections.js
module.exports.connections = {
mongo_development: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: '',
password: '',
database: 'my_local_db'
},
mongo_production: {
adapter: 'sails-mongo',
url: 'mongodb://me:mypw@foobar.mongohq.com:10052/my_production_db'
}
};
Couple of issues here:
connection
config key; it needs to be models.connection
.Putting the two together, you need a config/env/production.js file that looks like this:
module.exports = {
models: {
connection: 'mongo_production'
}
};
Then when lifting in production mode, models will use the mongo_production
connection by default.