stripe-archive / mosql

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

Querying a secondary server #54

Closed AndreaCrotti closed 10 years ago

AndreaCrotti commented 10 years ago

I'm trying to query a secondary server and it does not let me query it, the error is

/var/lib/gems/2.0.0/gems/mongo-1.10.2/lib/mongo/cursor.rb:149:in `next': not master and slaveOk=false (Mongo::ConnectionFailure)
    from /var/lib/gems/2.0.0/gems/mongo-1.10.2/lib/mongo/cursor.rb:334:in `each'
    from /var/lib/gems/2.0.0/gems/mongo-1.10.2/lib/mongo/db.rb:259:in `collect'
    from /var/lib/gems/2.0.0/gems/mongo-1.10.2/lib/mongo/db.rb:259:in `collection_names'
    from /var/lib/gems/2.0.0/gems/mongo-1.10.2/lib/mongo/db.rb:268:in `collections'
    from /var/lib/gems/2.0.0/gems/mosql-0.3.2/lib/mosql/streamer.rb:115:in `block in initial_import'
    from /var/lib/gems/2.0.0/gems/mosql-0.3.2/lib/mosql/streamer.rb:105:in `each'
    from /var/lib/gems/2.0.0/gems/mosql-0.3.2/lib/mosql/streamer.rb:105:in `initial_import'
    from /var/lib/gems/2.0.0/gems/mosql-0.3.2/lib/mosql/streamer.rb:28:in `import'
    from /var/lib/gems/2.0.0/gems/mosql-0.3.2/lib/mosql/cli.rb:162:in `run'
    from /var/lib/gems/2.0.0/gems/mosql-0.3.2/lib/mosql/cli.rb:16:in `run'
    from /var/lib/gems/2.0.0/gems/mosql-0.3.2/bin/mosql:5:in `<top (required)>'
    from /usr/local/bin/mosql:23:in `load'
    from /usr/local/bin/mosql:23:in `<main>'

Is there a way to tell to mosql to set that thing? (It's just rs.slaveOK() from the cli really). Thanks

nelhage commented 10 years ago

You can set ?slaveOk=true or ?readPreference=secondary in the connection URL.

nelhage commented 10 years ago

The README documents this at the bottom of the "Usage" section, but I'd be happy to hear ideas for how to make that more discoverable

AndreaCrotti commented 10 years ago

Ok thanks sorry it turns out I can also query the primary anyway. What do you mean with the last sentence? I don't see anything about slave in the README.. It could be in a FAQ section but it's more really a Mongo question in a way than a mosql question.

nelhage commented 10 years ago

The README documents ?readPreference=secondary and mentions doing initial imports against secondaries (mongo calls "slave" nodes secondaries, as of the "new" replication architecture)

AndreaCrotti commented 10 years ago

Ah sorry I was looking for "slave" in the page and was not finding it. Well as a FAQ there could be the error I reported and what is the option to pass to be more complete..

2014-08-21 18:10 GMT+01:00 Nelson Elhage notifications@github.com:

The README documents ?readPreference=secondary and mentions doing initial imports against secondaries (mongo calls "slave" nodes secondaries, as of the "new" replication architecture)

— Reply to this email directly or view it on GitHub https://github.com/stripe/mosql/issues/54#issuecomment-52951158.