Connection pool sharing among multiple mongolab databases
Hello,
I am using multiple mongolab databases in my app by using createConnection.
I am wondering whether is possible to share the connection pool among all the connections I am using.
I have given a look at useDb, but it is not what I am looking for, since it only allows to change the database name, whereas mongolab databases differ not only in name but in the whole url.
E.g.:
- mongodb://
: @ds0xxxxx.mongolab.com:xxxxx/database-1 - mongodb://
: @ds0yyyyy.mongolab.com:yyyyy/database-2
Any tips or suggestions?
Thanks in advance, David
It doesn't really make sense to have a connection pool that's connected to multiple URLs. The reasoning for having connection pools in the first place is you have a bunch of connections to a single URL, so if one fails you have a few other ones that are interchangeable. Having a connection pool to multiple independent servers thus doesn't really make sense with the way the mongodb driver thinks of connection pools.
Are these servers in the same repl set or sharded cluster?
Hi @vkarpov15,
First of all, thanks a lot for your answer.
Now I see that maybe I have misunderstood the sense of having connection pools. I thought about sharing connections among different databases because if I have 10 databases with a poolSize of 5 per each, I need to keep open 50 connections. By sharing the connection pool, instead, the same scenario would require only 15 connections.
At the moment the servers are all sandboxes on single nodes.
If you're concerned about the number of open connections, you can tweak the number of connections per pool, but we find that 5 is a reasonable default because the overhead of maintaining 5 connections per db is minimal in most cases.