Connect to a secondary mongodb server for reading


#1

Hi,

Anyone ever tried connecting to a secondary mongodb server using MongoInternals.RemoteCollectionDriver and do some reads? I’ve tried different connection strings and options but still I’m unable to make it work. I’ve dug deep through meteor code and seems url and options are being passed correctly to mongo driver. Not sure where the issue is.

Here’s a few connection strings I’ve tried:
mongodb://seconday.server:27017/dbname?slaveOk=true
mongodb://seconday.server:27017/dbname?readPreference=secondary
mongodb://primary.server:27017,seconday.server:27017/dbname?replicaSet=myset&readPreference=secondary

Also tried passing options to MongoInternals.RemoteCollectionDriver:
{ readPreference: “secondary”}
{ readPreference: “secondary”, slaveOk: true}
{ db: {readPreference: “secondary”}}

I’ve also tried combinations of both but still didn’t.

Error I’ve got for the connection string with replicaSet:
MongoError: no connection available

Errors for the rest is usually:
MongoError: not master and slaveOk=false

I’m using versions below:
Meteor: 1.5.2.2
MongoDB: 3.4 (both primary and secondary)

Pointing me to the right direction would be a big help.

Thanks!


#2

Hi @ianfynd,

I’m trying the same thing and finding the same issues as you.
Did you ever manage to make it work? Or find a workaround?

Thank you


#3

@nelsonuruworks unfortunately no. I ended up connecting directly to the primary. Please let me know if you find a solution.


#4

There isn’t anything theoretically wrong with connecting to a secondary when you specify a readpreference and have the list of hosts.

The bug is probably https://github.com/meteor/meteor/issues/9026