Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Multiple connections? #6

Open
demian85 opened this Issue · 6 comments

2 participants

@demian85

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?

Thanks.

@zzdhidden
Owner

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.

@demian85

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.
Thanks.

@zzdhidden
Owner

A example:

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

Right, might be useful some documentation! ...

@demian85

getting the following error...

/disk2/var/www/admin.nsmetrics.com/application/scripts/node_modules/mongoq/node_modules/mongodb/lib/mongodb/db.js:74
    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/admin.nsmetrics.com/application/scripts/node_modules/mongoq/node_modules/mongodb/lib/mongodb/db.js:74:11)
    at new db (/disk2/var/www/admin.nsmetrics.com/application/scripts/node_modules/mongoq/lib/db.js:45:18)
    at Object.twelections (/disk2/var/www/admin.nsmetrics.com/application/scripts/gnip-stream.js:218:14)
    at /disk2/var/www/admin.nsmetrics.com/application/scripts/node_modules/async/lib/async.js:467:24
    at /disk2/var/www/admin.nsmetrics.com/application/scripts/node_modules/async/lib/async.js:86:13
    at Array.forEach (native)
    at /disk2/var/www/admin.nsmetrics.com/application/scripts/node_modules/async/lib/async.js:26:24
    at Object.forEach (/disk2/var/www/admin.nsmetrics.com/application/scripts/node_modules/async/lib/async.js:85:9)
    at Object.parallel (/disk2/var/www/admin.nsmetrics.com/application/scripts/node_modules/async/lib/async.js:466:19)
    at Object._getExternalRules (/disk2/var/www/admin.nsmetrics.com/application/scripts/gnip-stream.js:189:9)
@zzdhidden
Owner

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
Something went wrong with that request. Please try again.