Skip to content

Commit d356355

Browse files
author
Brandon Black
committed
RUBY-494 rename all the things! standardizing class names across drivers
Mongo::Connection -> Mongo::MongoClient Mongo::ReplSetConnection -> Mongo::MongoReplicaSetClient Mongo::ShardedConnection -> Mongo::MongoShardedClient
1 parent eedcf8e commit d356355

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+270
-270
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](https://githu
4747
require 'rubygems'
4848
require 'mongo'
4949

50-
@client = Mongo::Client.new('localhost', 27017)
50+
@client = Mongo::MongoClient.new('localhost', 27017)
5151
@db = @client['sample-db']
5252
@coll = @db['test']
5353

@@ -154,7 +154,7 @@ timeout for waiting for old connections to be released to the pool.
154154
To set up a pooled connection to a single MongoDB instance:
155155

156156
```ruby
157-
@client = Client.new("localhost", 27017, :pool_size => 5, :timeout => 5)
157+
@client = MongoClient.new("localhost", 27017, :pool_size => 5, :timeout => 5)
158158
```
159159

160160
Though the pooling architecture will undoubtedly evolve, it currently owes much credit
@@ -168,13 +168,13 @@ of v1.3.0, the Ruby driver detects forking and reconnects automatically.
168168

169169
## Environment variable `MONGODB_URI`
170170

171-
`Mongo::Client.from_uri`, `Mongo::Client.new` and `Mongo::ReplSetClient.new` will use <code>ENV["MONGODB_URI"]</code> if no other args are provided.
171+
`Mongo::MongoClient.from_uri`, `Mongo::MongoClient.new` and `Mongo::MongoReplicaSetClient.new` will use <code>ENV["MONGODB_URI"]</code> if no other args are provided.
172172

173173
The URI must fit this specification:
174174

175175
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
176176

177-
If the type of connection (direct or replica set) should be determined entirely from <code>ENV["MONGODB_URI"]</code>, you may want to use `Mongo::Client.from_uri` because it will return either `Mongo::Client` or a `Mongo::ReplSetClient` depending on how many hosts are specified. Trying to use `Mongo::Client.new` with multiple hosts in <code>ENV["MONGODB_URI"]</code> will raise an exception.
177+
If the type of connection (direct or replica set) should be determined entirely from <code>ENV["MONGODB_URI"]</code>, you may want to use `Mongo::MongoClient.from_uri` because it will return either `Mongo::MongoClient` or a `Mongo::MongoReplicaSetClient` depending on how many hosts are specified. Trying to use `Mongo::MongoClient.new` with multiple hosts in <code>ENV["MONGODB_URI"]</code> will raise an exception.
178178

179179
## String Encoding
180180

@@ -204,10 +204,10 @@ generate _id values. If you want to control _id values or even their types,
204204
using a PK factory lets you do so.
205205

206206
You can tell the Ruby Mongo driver how to create primary keys by passing in
207-
the :pk option to the Client#db method.
207+
the :pk option to the MongoClient#db method.
208208

209209
```ruby
210-
db = Mongo::Client.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
210+
db = Mongo::MongoClient.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
211211
```
212212

213213
A primary key factory object must respond to :create_pk, which should
@@ -263,7 +263,7 @@ To turn on strict mode, either pass in :strict => true when obtaining a DB
263263
object or call the `:strict=` method:
264264

265265
```ruby
266-
db = Client.new('localhost', 27017).db('dbname', :strict => true)
266+
db = MongoClient.new('localhost', 27017).db('dbname', :strict => true)
267267
# I'm feeling lax
268268
db.strict = false
269269
# No, I'm not!
@@ -287,10 +287,10 @@ Notes:
287287
## Socket timeouts
288288

289289
The Ruby driver support timeouts on socket read operations. To enable them, set the
290-
`:op_timeout` option when you create a `Mongo::Client` object.
290+
`:op_timeout` option when you create a `Mongo::MongoClient` object.
291291

292292
If implementing higher-level timeouts, using tools like `Rack::Timeout`, it's very important
293-
to call `Mongo::Client#close` to prevent the subsequent operation from receiving the previous
293+
to call `Mongo::MongoClient#close` to prevent the subsequent operation from receiving the previous
294294
request.
295295

296296
# Testing

bin/mongo_console

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ require 'mongo'
1010
include Mongo
1111

1212
host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
13-
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
13+
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
1414
dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
1515

1616
puts "Connecting to #{host}:#{port} (CLIENT) on with database #{dbnm} (DB)"
17-
CLIENT = Client.new(host, port)
17+
CLIENT = MongoClient.new(host, port)
1818
DB = CLIENT.db(dbnm)
1919

2020
puts "Starting IRB session..."

examples/admin.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
include Mongo
77

88
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
9-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
9+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
1010

1111
puts "Connecting to #{host}:#{port}"
12-
client = Mongo::Client.new(host, port)
12+
client = Mongo::MongoClient.new(host, port)
1313
db = client.db('ruby-mongo-examples')
1414
coll = db.create_collection('test')
1515

examples/capped.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
include Mongo
55

66
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
7+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
88

99
puts "Connecting to #{host}:#{port}"
10-
db = Client.new(host, port).db('ruby-mongo-examples')
10+
db = MongoClient.new(host, port).db('ruby-mongo-examples')
1111
db.drop_collection('test')
1212

1313
# A capped collection has a max size and, optionally, a max number of records.

examples/cursor.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
include Mongo
77

88
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
9-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
9+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
1010

1111
puts "Connecting to #{host}:#{port}"
12-
db = Client.new(host, port).db('ruby-mongo-examples')
12+
db = MongoClient.new(host, port).db('ruby-mongo-examples')
1313
coll = db.collection('test')
1414

1515
# Erase all records from collection, if any

examples/gridfs.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ def assert
77
include Mongo
88

99
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
10-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
10+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
1111

1212
puts "Connecting to #{host}:#{port}"
13-
db = Client.new(host, port).db('ruby-mongo-examples')
13+
db = MongoClient.new(host, port).db('ruby-mongo-examples')
1414

1515
data = "hello, world!"
1616

examples/index_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
include Mongo
66

77
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
8+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
99

1010
puts ">> Connecting to #{host}:#{port}"
11-
db = Client.new(host, port).db('ruby-mongo-index_test')
11+
db = MongoClient.new(host, port).db('ruby-mongo-index_test')
1212

1313
class Exception
1414
def errmsg

examples/info.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
include Mongo
66

77
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
8+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
99

1010
puts "Connecting to #{host}:#{port}"
11-
db = Client.new(host, port).db('ruby-mongo-examples')
11+
db = MongoClient.new(host, port).db('ruby-mongo-examples')
1212
coll = db.collection('test')
1313

1414
# Erase all records from collection, if any

examples/queries.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
include Mongo
77

88
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
9-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
9+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
1010

1111
puts "Connecting to #{host}:#{port}"
12-
db = Client.new(host, port).db('ruby-mongo-examples')
12+
db = MongoClient.new(host, port).db('ruby-mongo-examples')
1313
coll = db.collection('test')
1414

1515
# Remove all records, if any

examples/replica_set.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
cons = []
55

66
10.times do
7-
cons << Mongo::ReplSetClient(['localhost:27017'], :read => :secondary)
7+
cons << Mongo::MongoReplicaSetClient(['localhost:27017'], :read => :secondary)
88
end
99

1010
ports = cons.map do |con|

examples/simple.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
include Mongo
77

88
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
9-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
9+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
1010

1111
puts "Connecting to #{host}:#{port}"
12-
db = Client.new(host, port).db('ruby-mongo-examples')
12+
db = MongoClient.new(host, port).db('ruby-mongo-examples')
1313
coll = db.collection('test')
1414

1515
# Erase all records from collection, if any

examples/strict.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
include Mongo
66

77
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
8+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
99

1010
puts "Connecting to #{host}:#{port}"
11-
db = Client.new(host, port).db('ruby-mongo-examples')
11+
db = MongoClient.new(host, port).db('ruby-mongo-examples')
1212

1313
db.drop_collection('does-not-exist')
1414
db.create_collection('test')

examples/types.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
include Mongo
77

88
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
9-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Client::DEFAULT_PORT
9+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
1010

1111
puts "Connecting to #{host}:#{port}"
12-
db = Client.new(host, port).db('ruby-mongo-examples')
12+
db = MongoClient.new(host, port).db('ruby-mongo-examples')
1313
coll = db.collection('test')
1414

1515
# Remove all records, if any

examples/web/thin/load.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'mongo')
22
require 'logger'
33

4-
$con = Mongo::ReplSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary, :refresh_mode => :sync, :refresh_interval => 30)
4+
$con = Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary, :refresh_mode => :sync, :refresh_interval => 30)
55
$db = $con['foo']
66

77
class Load < Sinatra::Base

examples/web/unicorn/load.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'mongo')
22

3-
$client = Mongo::Client.new('localhost', 27017)
3+
$client = Mongo::MongoClient.new('localhost', 27017)
44
$db = $client['foo']
55

66
class Load < Sinatra::Base

examples/web/unicorn/unicorn.rb.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ stdout_path "#{@dir}log/unicorn.stdout.log"
2323
# NOTE: You need this when using forking web servers!
2424
after_fork do |server, worker|
2525
$client.close if $client
26-
$client = Mongo::Client.new('localhost', 27017)
26+
$client = Mongo::MongoClient.new('localhost', 27017)
2727
$db = $client['foo']
2828
STDERR << "FORKED #{server} #{worker}"
2929
end

lib/mongo.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ module Constants
6666

6767

6868
require 'mongo/networking'
69-
require 'mongo/client'
70-
require 'mongo/repl_set_client'
71-
require 'mongo/sharded_client'
69+
require 'mongo/mongo_client'
70+
require 'mongo/mongo_replica_set_client'
71+
require 'mongo/mongo_sharded_client'
7272
require 'mongo/legacy'
7373
require 'mongo/collection'
7474
require 'mongo/cursor'

lib/mongo/db.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def strict?; @strict; end
4848
# The name of the database and the local write concern options.
4949
attr_reader :name, :write_concern
5050

51-
# The Mongo::Client instance connecting to the MongoDB server.
51+
# The Mongo::MongoClient instance connecting to the MongoDB server.
5252
attr_reader :connection
5353

5454
# The length of time that Collection.ensure_index should cache index calls
@@ -60,8 +60,8 @@ def strict?; @strict; end
6060
# Instances of DB are normally obtained by calling Mongo#db.
6161
#
6262
# @param [String] name the database name.
63-
# @param [Mongo::Client] client a connection object pointing to MongoDB. Note
64-
# that databases are usually instantiated via the Client class. See the examples below.
63+
# @param [Mongo::MongoClient] client a connection object pointing to MongoDB. Note
64+
# that databases are usually instantiated via the MongoClient class. See the examples below.
6565
#
6666
# @option opts [Boolean] :strict (False) If true, collections must exist to be accessed and must
6767
# not exist to be created. See DB#collection and DB#create_collection.
@@ -73,7 +73,7 @@ def strict?; @strict; end
7373
#
7474
# @option opts [Hash] :w, :j, :wtimeout, :fsync Set the default write concern for this database.
7575
# Propagated to Collection objects instantiated off of this DB. If no
76-
# options are provided, the default write concern set on this instance's Client object will be used. This
76+
# options are provided, the default write concern set on this instance's MongoClient object will be used. This
7777
# default can be overridden upon instantiation of any collection by explicitly setting write concern values
7878
# on initialization
7979
#
@@ -105,7 +105,7 @@ def initialize(name, client, opts={})
105105
# @param [String] username
106106
# @param [String] password
107107
# @param [Boolean] save_auth
108-
# Save this authentication to the client object using Client#add_auth. This
108+
# Save this authentication to the client object using MongoClient#add_auth. This
109109
# will ensure that the authentication will be applied on database reconnect. Note
110110
# that this value must be true when using connection pooling.
111111
#
@@ -215,7 +215,7 @@ def remove_user(username)
215215
end
216216

217217
# Deauthorizes use for this database for this client connection. Also removes
218-
# any saved authentication in the Client class associated with this
218+
# any saved authentication in the MongoClient class associated with this
219219
# database.
220220
#
221221
# @raise [MongoDBError] if logging out fails.

lib/mongo/gridfs/grid.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def initialize(db, fs_name=DEFAULT_FS_NAME)
4040

4141
# Create indexes only if we're connected to a primary node.
4242
connection = @db.connection
43-
if (connection.class == Client && connection.read_primary?) ||
44-
(connection.class == ReplSetClient && connection.primary)
43+
if (connection.class == MongoClient && connection.read_primary?) ||
44+
(connection.class == MongoReplicaSetClient && connection.primary)
4545
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
4646
end
4747
end

lib/mongo/gridfs/grid_file_system.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def initialize(db, fs_name=Grid::DEFAULT_FS_NAME)
4141

4242
# Create indexes only if we're connected to a primary node.
4343
connection = @db.connection
44-
if (connection.class == Client && connection.read_primary?) ||
45-
(connection.class == ReplSetClient && connection.primary)
44+
if (connection.class == MongoClient && connection.read_primary?) ||
45+
(connection.class == MongoReplicaSetClient && connection.primary)
4646
@files.create_index([['filename', 1], ['uploadDate', -1]])
4747
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
4848
end

lib/mongo/legacy.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def self.from_uri(uri = ENV['MONGODB_URI'], extra_opts={})
4242
end
4343

4444
module Mongo
45-
# @deprecated Use Mongo::Client instead. Support will be removed after v2.0
46-
class Connection < Client
45+
# @deprecated Use Mongo::MongoClient instead. Support will be removed after v2.0
46+
class Connection < MongoClient
4747
include Mongo::LegacyWriteConcern
4848

4949
def initialize(host=nil, port=nil, opts={})
@@ -52,8 +52,8 @@ def initialize(host=nil, port=nil, opts={})
5252
end
5353
end
5454

55-
# @deprecated Use Mongo::ReplSetClient instead. Support will be removed after v2.0
56-
class ReplSetConnection < ReplSetClient
55+
# @deprecated Use Mongo::MongoReplicaSetClient instead. Support will be removed after v2.0
56+
class ReplSetConnection < MongoReplicaSetClient
5757
include Mongo::LegacyWriteConcern
5858

5959
def initialize(*args)
@@ -66,8 +66,8 @@ def initialize(*args)
6666
end
6767
end
6868

69-
# @deprecated Use Mongo::ShardedClient instead. Support will be removed after v2.0
70-
class ShardedConnection < ShardedClient
69+
# @deprecated Use Mongo::MongoShardedClient instead. Support will be removed after v2.0
70+
class ShardedConnection < MongoShardedClient
7171
include Mongo::LegacyWriteConcern
7272

7373
def initialize(*args)

0 commit comments

Comments
 (0)