Multiple connections? #6

demian85 opened this Issue Mar 16, 2012 · 6 comments

2 participants


How to manage multiple connections? I don't get it. What is the pool size? I want to use the same connection for all databases, how can I do that?

var db = mongoq('mongodb://localhost/db1') // new connection
var db2 = mongoq('db2') // new connection or the same as above?



Hi, mongoq method will create new connection for db. It has not any public method for db with the same server(connection) now. You can create new connection like your sample. If you find that to do any inconvenience, Please provide examples, I will consider to fix it in the next version.

The pool size said that it will specify more connections in the pool to handle a large number of requests. You can find more docs in node-mongodb-native.


It's useless that way. I want to reuse the same connection or I will keep creating new ones when I try to select a database!
Please tell me how to create a single connection and use multiple databases.


A example:

var server = new mongoq.mongodb.Server('localhost', 27017);
var db1 = new mongoq.db("db1", server);
var db2 = new mongoq.db("db2", server);

Right, might be useful some documentation! ...


getting the following error...

    throw new Error("A Server or ReplSetServers instance cannot be shared acro
Error: A Server or ReplSetServers instance cannot be shared across multiple Db instances
    at new Db (/disk2/var/www/
    at new db (/disk2/var/www/
    at Object.twelections (/disk2/var/www/
    at /disk2/var/www/
    at /disk2/var/www/
    at Array.forEach (native)
    at /disk2/var/www/
    at Object.forEach (/disk2/var/www/
    at Object.parallel (/disk2/var/www/
    at Object._getExternalRules (/disk2/var/www/

At first, MongoQ depends on onde-mongodb-native.
It said that node-mongodb-native can't support multiple Db with the same server(connection).
It seems that you have to create two server to deal with the two databases...
Like your first example:

var db1 = mongoq('mongodb://localhost/db1')
var db2 = mongoq('mongodb://localhost/db2')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment