stripe-archive / mosql

MongoDB → PostgreSQL streaming replication
MIT License
1.63k stars 225 forks source link

Replicating from Mongo 1.8.2 #2

Closed mrgordon closed 11 years ago

mrgordon commented 11 years ago

I get "not master and slaveok=false" when I try to replicate from a secondary. I get "Invalid Mongo URI option readpreference" when I try to append "?readPreference=secondary" to the mongodb:// command line option.

Is there anyway around this if I need to replicate from a secondary with 1.8.2?

nelhage commented 11 years ago

Whoops. Looks like I trusted the docs, but didn't actually test that suggestion!

It looks like mongo-ruby-driver doesn't support ?readPreference in URIs. I've opened a bug with 10gen: https://jira.mongodb.org/browse/RUBY-547

In the meanwhile, you can use ?slaveOk=true in your connection strings. If you connect directly to a secondary, that will make the client not give that error, and if you connect to the replica set as a whole, that sets a "secondary-preferred" read preference, meaning it will try to read from a secondary if one is available.

I'll update the docs.

mrgordon commented 11 years ago

Thanks! Yeah a direct connection to a secondary gives the "not master and slaveok=false" response but slaveOk=true sounds like the way to go. Thanks!!

nelhage commented 11 years ago

Sorry, I was unclear -- a direct connection to a secondary with ?slaveOk=true should work. The option means slightly different things when connecting to a replSet versus directly -- when talking to a single node, it just means "It's OK if this node is a secondary".

mrgordon commented 11 years ago

Thanks. Worked correctly. I had to switch from zsh to bash for the query string to work. Really loving this. It's part of our migration path off of Mongo