Permalink
Browse files

Added support for a Replica Set

  • Loading branch information...
bkimble authored and bkeepers committed May 9, 2011
1 parent acaddeb commit b5c6ae835de7f9bdb8d79b2a090027137d6165ea
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/mongo_mapper/connection.rb
@@ -59,9 +59,14 @@ def config_for_environment(environment)
end
def connect(environment, options={})
- raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank?
+ raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank?
env = config_for_environment(environment)
- MongoMapper.connection = Mongo::Connection.new(env['host'], env['port'], options)
+ if env['hosts']
+ MongoMapper.connection = Mongo::ReplSetConnection.new(*env['hosts'])
+ else
+ MongoMapper.connection = Mongo::Connection.new(env['host'], env['port'], options)
+ end
+
MongoMapper.database = env['database']
MongoMapper.database.authenticate(env['username'], env['password']) if env['username'] && env['password']
end

0 comments on commit b5c6ae8

Please sign in to comment.