Reputation: 4538
I'm having difficulty connecting to a mongoid replicaset from a rails app.
I have the following config:
dev1:
clients:
default:
database: opera_bounties_dev1
hosts:
- 10.0.0.1:27017
- 10.0.0.2:27017
# read: :secondary
# slave_ok: true
options:
# read: :secondary
replicaSet: operaeventrsX
consistency: :strong
pool_size: 200
# slave_ok: true
# connect: :replica_set
I can connect to the primary just fine, but if I shut down the primary, I cannot connect to the secondary. Now if I connect via mongo shell to the secondary and issue rs.slaveOk()
, I can connect to the secondary for that one session. I need my rails app to connect to mongo with slaveOk always. setting slave_ok: true
in the configuration (above) doesn't do it... What is the trick here?
Upvotes: 0
Views: 1439
Reputation: 4538
The working config is:
dev1:
clients:
default:
database: dbname_dev1
hosts:
- 10.0.0.1:27017
- 10.0.0.2:27017
options:
read:
mode: :secondary_preferred
consistency: :strong
pool_size: 200
connect: :replica_set
replica_set: replicaSetName
Upvotes: 2