I'm new to sailsjs but I had similar problem with mongodb so, I started to dig into sails source code and found this. (please correct me if I'm wrong)
Each sails model you create(generate) is bound with connection object. This defines adapter that whatever you config in adapter config file.
Referring to sails doc "custom adapter"
Custom-adapters must have properties pointing db instance.
In summary, you can access it through
YourModelName.connections.dbNameFromConfigfile
e.g.
adapter.js (0.9) or connection.js (0.10.x)
module.exports.connections = {
someMongodbServer: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
// user: 'username',
// password: 'password',
database: 'fileDb'
},
};
File.js (Model)
module.exports = {
}
FileController.js (Controller)
module.exports = {
upload: function(req, res){
var db = File.connections.someMongodbServer; // name at config file
your code here....
}
}