Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replica set connection issue #374

Open
ppounder opened this issue Jul 11, 2016 · 6 comments
Open

Replica set connection issue #374

ppounder opened this issue Jul 11, 2016 · 6 comments
Labels
Documentation Hacktoberfest Good issue for participating in Hacktoberfest

Comments

@ppounder
Copy link

ppounder commented Jul 11, 2016

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

@ppounder
Copy link
Author

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?

@malarzm
Copy link
Member

malarzm commented Aug 26, 2016

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

@ppounder
Copy link
Author

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?

@malarzm
Copy link
Member

malarzm commented Aug 26, 2016

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 :)

@jwage jwage added the Hacktoberfest Good issue for participating in Hacktoberfest label Oct 2, 2018
@stale
Copy link

stale bot commented Jan 21, 2019

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.

@stale stale bot added the Stale Issues that have not seen any activity in 30 days label Jan 21, 2019
@alcaeus
Copy link
Member

alcaeus commented Jan 21, 2019

I believe adding a link to the connection string reference in the MongoDB docs should help in the future. Adding to the roadmap.

@stale stale bot removed the Stale Issues that have not seen any activity in 30 days label Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Hacktoberfest Good issue for participating in Hacktoberfest
Projects
None yet
Development

No branches or pull requests

4 participants