mongoid / moped

A MongoDB driver for Ruby
https://mongoid.github.io/old/en/moped/
MIT License
201 stars 153 forks source link

Moped::Errors::ConnectionFailure: Could not connect to any secondary or primary nodes for replica set #306

Open AvnerCohen opened 10 years ago

AvnerCohen commented 10 years ago

Getting this error when moving from MongoDriver to Moped.

The behaviour is very weird, because I can totally get this to work with MongoDriver, but with moped (no mongoid) something is not working:

MongoDriver Flow:

> mongo_client = Mongo::Connection.new("slave", "27017").db("database_name")
> mongo_client["collection_123"].find_one
=> {"data" = > "Good Data"}

Moped Flow:

> mongo_client = Moped::Session.new(["slave:27017"], database: "database_name")
> session["collection_123"].find().first rescue "Failed"
=> "Failed"
(with Moped::Errors::ConnectionFailure: Could not connect to any secondary or primary nodes for replica set)

However, When I add the master as well (or use master only) this works:

> mongo_client = Moped::Session.new(["master:27017"], database: "database_name")
> session["collection_123"].find().first rescue "Failed"
=> {"data" = > "Good Data"}

> mongo_client = Moped::Session.new(["master:27017", slave:27017"], database: "database_name")
> session["collection_123"].find().first rescue "Failed"
=> {"data" = > "Good Data"}

Am I expecting something weird from Moped?

arthurnn commented 10 years ago

Are you still using master/slave setup on MongoDB? and not primary, secondary?

AvnerCohen commented 10 years ago

I do. While majority of the stuff is already migrated to ReplicaSets, not all of it had.. As far as I read, this is still a supported setup as per mongodb (although, not recommended one).