{"action":"created","issue":{"url":"https://api.github.com/repos/LearnBoost/mongoose/issues/2673","labels_url":"https://api.github.com/repos/LearnBoost/mongoose/issues/2673/labels{/name}","comments_url":"https://api.github.com/repos/LearnBoost/mongoose/issues/2673/comments","events_url":"https://api.github.com/repos/LearnBoost/mongoose/issues/2673/events","html_url":"https://github.com/LearnBoost/mongoose/issues/2673","id":57462517,"number":2673,"title":"Cannot connect to multiple databases on different hosts","user":{"login":"dobre-robert-marius","id":7329292,"avatar_url":"https://avatars.githubusercontent.com/u/7329292?v=3","gravatar_id":"","url":"https://api.github.com/users/dobre-robert-marius","html_url":"https://github.com/dobre-robert-marius","followers_url":"https://api.github.com/users/dobre-robert-marius/followers","following_url":"https://api.github.com/users/dobre-robert-marius/following{/other_user}","gists_url":"https://api.github.com/users/dobre-robert-marius/gists{/gist_id}","starred_url":"https://api.github.com/users/dobre-robert-marius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobre-robert-marius/subscriptions","organizations_url":"https://api.github.com/users/dobre-robert-marius/orgs","repos_url":"https://api.github.com/users/dobre-robert-marius/repos","events_url":"https://api.github.com/users/dobre-robert-marius/events{/privacy}","received_events_url":"https://api.github.com/users/dobre-robert-marius/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-12T13:53:22Z","updated_at":"2015-02-12T17:27:09Z","closed_at":null,"body":"I have a node js app built on express and mongoose. Until now, i was using mongoose.connect(uri, options) to make a db connection. But from now on, i want to be able to connect to multiple databases on multiple hosts. Everything is working fine if i'm on the same host ( i use mongoose.createConnection(uri, options) ). For production databases stored on the same host or for localhost databases everything is fine. The problem appears if i try to connect to one localhost database and one remote database, instead of both on the same host.\r\n\r\nDbConnection file:\r\n```\r\n     this.sharedDbConnection = this.mongooseConnection.createConnection('sharedDb');\r\n     this.defaultDbConnection = this.mongooseConnection.createConnection('mongodb');\r\n```\r\n\r\nMongooseConnection file:\r\n```\r\nfunction getConnectionUrl(config) {\r\n\r\n    return 'mongodb://' + config.user + ':' + config.password + '@' + config.host + ':' + config.port + '/' + config.dbName;\r\n}\r\n\r\nMongooseConnection.prototype.createConnection = function(dbName) {\r\n\r\n    var connection = this.mongoose.createConnection(getConnectionUrl(this.config[dbName]), this.mongooseConfig, function(err) {\r\n\r\n        if(err) {\r\n\r\n            console.log(err);\r\n\r\n        } else {\r\n\r\n            console.log('connected with createConnection on ', dbName);\r\n\r\n        }\r\n\r\n    });\r\n\r\n    return connection;\r\n\r\n};\r\n```\r\n\r\nMongooseConfig file:\r\n```\r\n{\r\n    server: {\r\n        poolSize:      10,\r\n        socketOptions: {\r\n            keepAlive: 1\r\n        }\r\n    },\r\n    db:     {\r\n        numberOfRetries:  10,\r\n        retryMiliSeconds: 1000\r\n    },\r\n    auth:   false\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/LearnBoost/mongoose/issues/comments/74113397","html_url":"https://github.com/LearnBoost/mongoose/issues/2673#issuecomment-74113397","issue_url":"https://api.github.com/repos/LearnBoost/mongoose/issues/2673","id":74113397,"user":{"login":"dobre-robert-marius","id":7329292,"avatar_url":"https://avatars.githubusercontent.com/u/7329292?v=3","gravatar_id":"","url":"https://api.github.com/users/dobre-robert-marius","html_url":"https://github.com/dobre-robert-marius","followers_url":"https://api.github.com/users/dobre-robert-marius/followers","following_url":"https://api.github.com/users/dobre-robert-marius/following{/other_user}","gists_url":"https://api.github.com/users/dobre-robert-marius/gists{/gist_id}","starred_url":"https://api.github.com/users/dobre-robert-marius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobre-robert-marius/subscriptions","organizations_url":"https://api.github.com/users/dobre-robert-marius/orgs","repos_url":"https://api.github.com/users/dobre-robert-marius/repos","events_url":"https://api.github.com/users/dobre-robert-marius/events{/privacy}","received_events_url":"https://api.github.com/users/dobre-robert-marius/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T17:27:09Z","updated_at":"2015-02-12T17:27:09Z","body":"I can connect to a remote db. If i put in the config file 2 remote dbs or 2 local dbs, everything is working as expected. Only if  i put 2 different hosts i will not be able to access both of them."}}