scttnlsn/monq

Connecting to a Replica Set DB

Closed this issue · 2 comments

'ello!

Is there a way to use a replica set as the queue DB? I'm attempting to use one at the moment by passing in the URI mongodb://db1.example.com:27017,db2.example.com:27018,db3.example.com:27019,db4.example.com:27020/?replicaSet=rs0 but it never connects and then eventually times out.

I can connect to the same replica set DB directly through Mongoskin, though I do that by passing it an object of replica set servers.

So is there a way to connect to a replica set DB through Monq? :)

Thanks

My issue turned out to be a not-so-common "problem" with the native MongoDB driver.

In my node application, I use the same database for a number of different collections and uses. With Monq on top, it turned out that I was connecting to said database more than once. While that's usually acceptable for usual connections, this database is a replica set; it appears that replica sets can only be connected to once, otherwise they'll throw the in process of connection error.

I ended up solving this by connecting to the DB once via Mongoskin as was required by my application, then sending that DB connection directly to Monq after having adjusted the connection.js file to accept both a URI to connect to and an already-made connection.

Would it be worth submitting a pull request for this? It'd be useful for making multiple references to a replica set DB where Monq is at least one of those references.

@jpwilliams Yeah- definitely. It'd be great if the Connection constructor accepted a URL or an existing connection object.