diff --git a/docs/READ_PREFERENCE.md b/docs/READ_PREFERENCE.md index eedb7c3..7d77a7b 100644 --- a/docs/READ_PREFERENCE.md +++ b/docs/READ_PREFERENCE.md @@ -17,7 +17,7 @@ The Ruby driver allows you to set read preference on each of four levels: the co Objects will inherit the default read preference from their parents. Thus, if you set a read preference of `{:read => :secondary}` when creating a new connection, then all databases and collections created from that connection will inherit the same setting. See this code example: - @con = Mongo::ReplSetConnection.new([['localhost', 27017], ['localhost', 27018]], :read => :secondary) + @con = Mongo::ReplSetConnection.new(['localhost:27017','localhost:27018'], :read => :secondary) @db = @con['test'] @collection = @db['foo'] @collection.find({:name => 'foo'}) diff --git a/docs/REPLICA_SETS.md b/docs/REPLICA_SETS.md index 6ea0bf8..c6a1ca3 100644 --- a/docs/REPLICA_SETS.md +++ b/docs/REPLICA_SETS.md @@ -11,13 +11,13 @@ takes a list of seed nodes followed by any connection options. You'll want to sp the driver more chances to connect in the event that any one seed node is offline. Once the driver connects, it will cache the replica set topology as reported by the given seed node and use that information if a failover is later required. - @connection = ReplSetConnection.new(['n1.mydb.net', 27017], ['n2.mydb.net', 27017], ['n3.mydb.net', 27017]) + @connection = ReplSetConnection.new(['n1.mydb.net:27017', 'n2.mydb.net:27017', 'n3.mydb.net:27017']) ### Read slaves If you want to read from a secondary node, you can pass :read => :secondary to ReplSetConnection#new. - @connection = ReplSetConnection.new(['n1.mydb.net', 27017], ['n2.mydb.net', 27017], ['n3.mydb.net', 27017], + @connection = ReplSetConnection.new(['n1.mydb.net:27017', 'n2.mydb.net:27017', 'n3.mydb.net:27017'], :read => :secondary) A random secondary will be chosen to be read from. In a typical multi-process Ruby application, you'll have a good distribution of reads across secondary nodes. @@ -48,18 +48,18 @@ having to manually restart your app server, then you should enable it. You can e synchronously, which will refresh the replica set data in a synchronous fashion (which may ocassionally slow down your queries): - @connection = ReplSetConnection.new(['n1.mydb.net', 27017], :refresh_mode => :sync) + @connection = ReplSetConnection.new(['n1.mydb.net:27017'], :refresh_mode => :sync) If you want to change the default refresh interval of 90 seconds, you can do so like this: - @connection = ReplSetConnection.new(['n1.mydb.net', 27017], :refresh_mode => :sync, + @connection = ReplSetConnection.new(['n1.mydb.net:27017'], :refresh_mode => :sync, :refresh_interval => 60) Do not set this value to anything lower than 30, or you may start to experience performance issues. You can also disable refresh mode altogether: - @connection = ReplSetConnection.new(['n1.mydb.net', 27017], :refresh_mode => false) + @connection = ReplSetConnection.new(['n1.mydb.net:27017'], :refresh_mode => false) And you can call `refresh` manually on any replica set connection: diff --git a/lib/mongo/repl_set_connection.rb b/lib/mongo/repl_set_connection.rb index 6830e5e..6ceeac3 100644 --- a/lib/mongo/repl_set_connection.rb +++ b/lib/mongo/repl_set_connection.rb @@ -67,13 +67,13 @@ module Mongo # @example Connect to a replica set and provide two seed nodes. Note that the number of seed nodes does # not have to be equal to the number of replica set members. The purpose of seed nodes is to permit # the driver to find at least one replica set member even if a member is down. - # ReplSetConnection.new(['localhost', 30000], ['localhost', 30001]) + # ReplSetConnection.new(['localhost:30000', 'localhost:30001']) # # @example Connect to a replica set providing two seed nodes and ensuring a connection to the replica set named 'prod': - # ReplSetConnection.new(['localhost', 30000], ['localhost', 30001], :name => 'prod') + # ReplSetConnection.new(['localhost:30000', 'localhost:30001'], :name => 'prod') # # @example Connect to a replica set providing two seed nodes and allowing reads from a secondary node: - # ReplSetConnection.new(['localhost', 30000], ['localhost', 30001], :read => :secondary) + # ReplSetConnection.new(['localhost:30000', 'localhost:30001'], :read => :secondary) # # @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby # diff --git a/test/unit/read_test.rb b/test/unit/read_test.rb index 1d00a03..dbd86b7 100644 --- a/test/unit/read_test.rb +++ b/test/unit/read_test.rb @@ -13,7 +13,7 @@ class ReadTest < Test::Unit::TestCase context "Read mode on replica set connection: " do setup do @read_preference = :secondary - @con = Mongo::ReplSetConnection.new(['localhost', 27017], :read => @read_preference, :connect => false) + @con = Mongo::ReplSetConnection.new(['localhost:27017'], :read => @read_preference, :connect => false) end should "store read preference on Connection" do