Replica set connection issue
Hi there,
I'm trying to connect to my replica set within Symfony. I have my config settings as follows as per http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/config.html#connecting-to-a-pool-of-mongodb-servers-on-1-connection
connections:
default:
server: 'mongodb://*.*.*.1:27017,*.*.*.2:27017,*.*.*.3:27017'
However I get the error:
Uncaught PHP Exception MongoException: "Cannot run command count(): not master and slaveOk=false"
Let me add a bit of context. Primary is *.*.*.1 and I want to be able to connect via *.*.*.2 or *.*.*.3 if primary goes down and one of the secondaries then become primary. If I go with just the primary mongo server IP address, instead of a comma'd list of my servers, I can connect fine, but that fails if *.*.*.1 goes down and *.*.*.2 becomes primary for example.
Has anyone any suggestions?
Regards Paul Pounder
To add further, I've added readPreference: primary but still getting the same issue. Seems to round robin all my requests to each server in the list, not knowing which is primary.
Does the replicaSet: repl-set-name have to be configured? Will this tell my config which is primary?
FWIW I'm using following DSN: u:p@somewhere-s1:29629,somewhere-s2:29629/?replicaSet=rs-name&readPreference=primaryPreferred and it's working as expected so yes, I'd try adding replicaSet
Good news is that adding replicaSet has resolved our issue. However if you don't add replicaSet config setting it seems to ignore readPreferences and round robins to the mongo server names listed in the server config setting. Wonder whether this needs a documentation update or is my reading of this incorrect?
I think this is just how mongo driver behaves but I don't mind adding a tip in our docs if we have something more on replica sets :)
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.
I believe adding a link to the connection string reference in the MongoDB docs should help in the future. Adding to the roadmap.