mongo 1.6.2 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/README.md +44 -22
  2. data/Rakefile +17 -4
  3. data/docs/GridFS.md +2 -2
  4. data/docs/HISTORY.md +15 -1
  5. data/docs/RELEASES.md +4 -4
  6. data/docs/TUTORIAL.md +12 -0
  7. data/docs/WRITE_CONCERN.md +1 -1
  8. data/lib/mongo/collection.rb +1 -1
  9. data/lib/mongo/connection.rb +35 -47
  10. data/lib/mongo/cursor.rb +10 -9
  11. data/lib/mongo/db.rb +1 -1
  12. data/lib/mongo/gridfs/grid_ext.rb +4 -4
  13. data/lib/mongo/gridfs/grid_file_system.rb +3 -3
  14. data/lib/mongo/gridfs/grid_io.rb +1 -1
  15. data/lib/mongo/networking.rb +5 -0
  16. data/lib/mongo/repl_set_connection.rb +47 -21
  17. data/lib/mongo/util/conversions.rb +23 -0
  18. data/lib/mongo/util/logging.rb +13 -18
  19. data/lib/mongo/util/node.rb +1 -5
  20. data/lib/mongo/util/pool.rb +0 -1
  21. data/lib/mongo/util/ssl_socket.rb +3 -1
  22. data/lib/mongo/util/support.rb +1 -0
  23. data/lib/mongo/util/tcp_socket.rb +15 -32
  24. data/lib/mongo/util/uri_parser.rb +100 -35
  25. data/lib/mongo/version.rb +1 -1
  26. data/test/auxillary/1.4_features.rb +1 -1
  27. data/test/auxillary/authentication_test.rb +1 -1
  28. data/test/auxillary/autoreconnect_test.rb +1 -1
  29. data/test/auxillary/fork_test.rb +1 -1
  30. data/test/auxillary/repl_set_auth_test.rb +1 -1
  31. data/test/auxillary/slave_connection_test.rb +1 -1
  32. data/test/auxillary/threaded_authentication_test.rb +1 -1
  33. data/test/bson/binary_test.rb +1 -1
  34. data/test/bson/bson_test.rb +8 -1
  35. data/test/bson/byte_buffer_test.rb +1 -1
  36. data/test/bson/hash_with_indifferent_access_test.rb +1 -1
  37. data/test/bson/json_test.rb +1 -1
  38. data/test/bson/object_id_test.rb +11 -1
  39. data/test/bson/ordered_hash_test.rb +1 -1
  40. data/test/bson/timestamp_test.rb +1 -1
  41. data/test/collection_test.rb +1 -1
  42. data/test/connection_test.rb +25 -1
  43. data/test/conversions_test.rb +1 -1
  44. data/test/cursor_fail_test.rb +1 -1
  45. data/test/cursor_message_test.rb +1 -1
  46. data/test/cursor_test.rb +1 -1
  47. data/test/db_api_test.rb +57 -3
  48. data/test/db_connection_test.rb +1 -1
  49. data/test/db_test.rb +1 -1
  50. data/test/grid_file_system_test.rb +1 -1
  51. data/test/grid_io_test.rb +30 -1
  52. data/test/grid_test.rb +1 -1
  53. data/test/pool_test.rb +1 -1
  54. data/test/replica_sets/basic_test.rb +10 -0
  55. data/test/replica_sets/connect_test.rb +45 -0
  56. data/test/replica_sets/read_preference_test.rb +2 -1
  57. data/test/replica_sets/refresh_with_threads_test.rb +2 -0
  58. data/test/replica_sets/rs_test_helper.rb +1 -1
  59. data/test/safe_test.rb +1 -1
  60. data/test/support_test.rb +1 -1
  61. data/test/threading/threading_with_large_pool_test.rb +1 -1
  62. data/test/threading_test.rb +1 -1
  63. data/test/timeout_test.rb +1 -1
  64. data/test/tools/repl_set_manager.rb +1 -0
  65. data/test/unit/collection_test.rb +1 -1
  66. data/test/unit/connection_test.rb +89 -1
  67. data/test/unit/cursor_test.rb +1 -1
  68. data/test/unit/db_test.rb +1 -1
  69. data/test/unit/grid_test.rb +1 -1
  70. data/test/unit/node_test.rb +1 -1
  71. data/test/unit/pool_manager_test.rb +1 -1
  72. data/test/unit/pool_test.rb +1 -1
  73. data/test/unit/read_test.rb +1 -1
  74. data/test/unit/safe_test.rb +1 -1
  75. data/test/uri_test.rb +25 -5
  76. metadata +5 -5
data/README.md CHANGED
@@ -1,21 +1,42 @@
1
+ # Documentation
2
+
3
+ This API documentation is available online at [http://api.mongodb.org/ruby](http://api.mongodb.org/ruby)
4
+ for all releases of the MongoDB Ruby driver. Please reference the exact version of the documentation
5
+ that matches the release of the Ruby driver that you are using. Note that the
6
+ [Ruby Language Center for MongoDB](http://www.mongodb.org/display/DOCS/Ruby+Language+Center)
7
+ has a link to API Documentation for the current release.
8
+
9
+ If you have the source, you can generate the matching documentation by typing
10
+
11
+ $ rake ydoc
12
+
13
+ Then open the file ydoc/index.html in your browser.
14
+
1
15
  # Introduction
2
16
 
3
17
  This is the 10gen-supported Ruby driver for [MongoDB](http://www.mongodb.org).
4
18
 
5
- This documentation includes other articles of interest, include:
19
+ For the reference manual, use the links in the upper-left and upper-right corners for quick navigation to the following.
20
+
21
+ * [Alphabetic Index](_index.html)
22
+ * [Class List](class_list.html)
23
+ * [Method List](method_list.html)
24
+ * [File List](file_list.html)
6
25
 
7
- 1. [A tutorial](http://api.mongodb.org/ruby/current/file.TUTORIAL.html).
8
- 2. [Replica Sets in Ruby](http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html).
9
- 3. [Write Concern in Ruby](http://api.mongodb.org/ruby/current/file.WRITE_CONCERN.html).
10
- 4. [Tailable Cursors in Ruby](http://api.mongodb.org/ruby/current/file.TAILABLE_CURSORS.html).
11
- 5. [Read Preference in Ruby](http://api.mongodb.org/ruby/current/file.READ_PREFERENCE.html).
12
- 6. [GridFS in Ruby](http://api.mongodb.org/ruby/current/file.GridFS.html).
13
- 7. [Frequently Asked Questions](http://api.mongodb.org/ruby/current/file.FAQ.html).
14
- 8. [History](http://api.mongodb.org/ruby/current/file.HISTORY.html).
15
- 9. [Release plan](http://api.mongodb.org/ruby/current/file.RELEASES.html).
16
- 10. [Credits](http://api.mongodb.org/ruby/current/file.CREDITS.html).
26
+ This documentation has other articles of interest, including:
17
27
 
18
- Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](http://api.mongodb.org/ruby/current/file.TUTORIAL.html)
28
+ 1. [A tutorial](docs/TUTORIAL.md).
29
+ 2. [Replica Sets in Ruby](docs/REPLICA_SETS.md).
30
+ 3. [Write Concern in Ruby](docs/WRITE_CONCERN.md).
31
+ 4. [Tailable Cursors in Ruby](docs/TAILABLE_CURSORS.md).
32
+ 5. [Read Preference in Ruby](docs/READ_PREFERENCE.md).
33
+ 6. [GridFS in Ruby](docs/GridFS.md).
34
+ 7. [Frequently Asked Questions](docs/FAQ.md).
35
+ 8. [History](docs/HISTORY.md).
36
+ 9. [Release plan](docs/RELEASES.md).
37
+ 10. [Credits](docs/CREDITS.md).
38
+
39
+ Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](docs/TUTORIAL.md)
19
40
  for much more:
20
41
 
21
42
  require 'rubygems'
@@ -83,7 +104,7 @@ That's all there is to it!
83
104
 
84
105
  # Examples
85
106
 
86
- For extensive examples, see the [MongoDB Ruby Tutorial](http://www.mongodb.org/display/DOCS/Ruby+Tutorial).
107
+ For extensive examples, see the [MongoDB Ruby Tutorial](http://api.mongodb.org/ruby/current/file.TUTORIAL.html).
87
108
 
88
109
  Bundled with the driver are many examples, located in the "docs/examples" subdirectory. Samples include using
89
110
  the driver and using the GridFS class GridStore. MongoDB must be running for
@@ -152,6 +173,16 @@ Certain Ruby application servers work by forking, and it has long been necessary
152
173
  re-establish the child process's connection to the database after fork. But with the release
153
174
  of v1.3.0, the Ruby driver detects forking and reconnects automatically.
154
175
 
176
+ ## Environment variable `MONGODB_URI`
177
+
178
+ `Mongo::Connection.from_uri`, `Mongo::Connection.new` and `Mongo::ReplSetConnection.new` will use <code>ENV["MONGODB_URI"]</code> if no other args are provided.
179
+
180
+ The URI must fit this specification:
181
+
182
+ mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
183
+
184
+ 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::Connection.from_uri` because it will return either `Mongo::Connection` or a `Mongo::ReplSetConnection` depending on how many hosts are specified. Trying to use `Mongo::Connection.new` with multiple hosts in <code>ENV["MONGODB_URI"]</code> will raise an exception.
185
+
155
186
  ## String Encoding
156
187
 
157
188
  The BSON ("Binary JSON") format used to communicate with Mongo requires that
@@ -300,15 +331,6 @@ If you want to test replica set, you can run the following task:
300
331
 
301
332
  $ rake test:rs
302
333
 
303
- # Documentation
304
-
305
- This documentation is available online at [http://api.mongodb.org/ruby](http://api.mongodb.org/ruby). You can
306
- generate the documentation if you have the source by typing
307
-
308
- $ rake ydoc
309
-
310
- Then open the file +ydoc/index.html+.
311
-
312
334
  # Release Notes
313
335
 
314
336
  See HISTORY.
data/Rakefile CHANGED
@@ -7,19 +7,32 @@ end
7
7
  require 'fileutils'
8
8
  require 'rake/testtask'
9
9
  require 'rake'
10
+ require 'rake/extensiontask'
11
+ require 'rake/javaextensiontask'
10
12
 
11
13
  begin
12
14
  require 'git'
13
- rescue LoadError
14
- end
15
-
16
- begin
15
+ require 'devkit'
17
16
  require 'ci/reporter/rake/test_unit'
18
17
  rescue LoadError
19
18
  end
20
19
 
21
20
  ENV['TEST_MODE'] = 'TRUE'
22
21
 
22
+ Rake::ExtensionTask.new('cbson') do |ext|
23
+ ext.lib_dir = "lib/bson_ext"
24
+ end
25
+
26
+ #Rake::JavaExtensionTask.new('jbson') do |ext| # not yet functional
27
+ # ext.ext_dir = 'ext/src/org/jbson'
28
+ #end
29
+
30
+ desc "Compiles and tests MongoDB Ruby driver w/ C extensions."
31
+ task :c do
32
+ Rake::Task['compile:cbson'].invoke
33
+ Rake::Task['test:c'].invoke
34
+ end
35
+
23
36
  task :java do
24
37
  Rake::Task['build:java'].invoke
25
38
  Rake::Task['test:ruby'].invoke
@@ -88,7 +88,7 @@ Deleting a file is as simple as providing the id:
88
88
 
89
89
  ### The GridFileSystem class
90
90
 
91
- [GridFileSystem](http://api.mongodb.org/ruby/current/Mongo/GridFileSystem.html) is a light emulation of a file system and therefore has a couple of unique properties. The first is that filenames are assumed to be unique. The second, a consequence of the first, is that files are versioned. To see what this means, let's create a GridFileSystem instance:
91
+ [GridFileSystem](Mongo/GridFileSystem.html) is a light emulation of a file system and therefore has a couple of unique properties. The first is that filenames are assumed to be unique. The second, a consequence of the first, is that files are versioned. To see what this means, let's create a GridFileSystem instance:
92
92
 
93
93
  #### Saving files
94
94
 
@@ -154,5 +154,5 @@ All of the options for storing metadata and saving in safe mode are available fo
154
154
 
155
155
  ### Advanced Users
156
156
 
157
- Astute code readers will notice that the Grid and GridFileSystem classes are merely thin wrappers around an underlying [GridIO class](http://api.mongodb.org/ruby/current/Mongo/GridIO.html). This means that it's easy to customize the GridFS implementation presented here; just use GridIO for all the low-level work, and build the API you need in an external manager class similar to Grid or GridFileSystem.
157
+ Astute code readers will notice that the Grid and GridFileSystem classes are merely thin wrappers around an underlying [GridIO class](Mongo/GridIO.html). This means that it's easy to customize the GridFS implementation presented here; just use GridIO for all the low-level work, and build the API you need in an external manager class similar to Grid or GridFileSystem.
158
158
 
@@ -1,10 +1,24 @@
1
1
  # MongoDB Ruby Driver History
2
2
 
3
+ ### 1.6.3
4
+ 2012-06-05
5
+
6
+ * Performance measurements and enhancements (especially for C-extensions)
7
+ * Bug fixes for checking strings with non UTF-8 forced or implied encodings
8
+ * Added refresh support for multiple threaded instances of ReplSetConnection
9
+ * Added ability to handle IRB::Abort Exception (ctrl-c) cleanly
10
+ * Added support for large dates on 32-bit platforms (Ruby 1.9+)
11
+ * Added #to_ary method for BSON::ObjectId (Farrel Lifson)
12
+ * Added support for ENV['MONGODB_URI'] (Seamus Abshere)
13
+ * Various gridio bug fixes (John Bintz)
14
+ * Various logging support improvements
15
+ * Various documentation improvements (tutorials, sorting, links)
16
+
3
17
  ### 1.6.2
4
18
  2012-04-05
5
19
 
6
20
  * Implements socket timeouts via non-blocking IO instead of Timeout module
7
- which should greately increase performance in highly threaded applications
21
+ which should greatly increase performance in highly threaded applications
8
22
  * Added ability to authentication via secondary if primary node unavailable
9
23
  * Replica set refresh interval now enforces a lower bound of 60 seconds
10
24
  * Added documentation for dropping indexes, collections, databases
@@ -26,9 +26,9 @@ Before each relese to Rubygems.org, the following steps will be taken:
26
26
 
27
27
  2. Update the HISTORY file and document all significant commits.
28
28
 
29
- 3. Update the version in lib/bson.rb, lib/mongo/version.rb, and ext/version.h.
29
+ 3. Update the version in lib/bson.rb, lib/mongo/version.rb, and ext/cbson/version.h.
30
30
 
31
- 4. Commit: "Release [VERSION]"
31
+ 4. Commit: "RELEASE [VERSION]"
32
32
 
33
33
  5. git tag [version]
34
34
 
@@ -36,7 +36,7 @@ Before each relese to Rubygems.org, the following steps will be taken:
36
36
 
37
37
  7. Push tags and commit to GitHub (git push origin master, git push --tags).
38
38
 
39
- 8. Build and push docs.
39
+ 8. Build and push docs. (git: mongodb/apidocs)
40
40
 
41
41
  9. Push gems to Rubygems.org.
42
42
 
@@ -47,7 +47,7 @@ Before each relese to Rubygems.org, the following steps will be taken:
47
47
  12. Annouce release on mongodb-user and mongodb-dev.
48
48
 
49
49
  ## Rake Deploy Tasks
50
- 1. rake deploy:change_version[1.6.1]
50
+ 1. rake deploy:change_version[x.x.x]
51
51
  2. rake deploy:git_prepare
52
52
  3. rake deploy:git_push
53
53
  4. rake deploy:gem_build
@@ -170,6 +170,18 @@ and it should just print just one document:
170
170
 
171
171
  {"_id"=>BSON::ObjectId('4f7b20b4e4d30b35c9000049'), "i"=>71}
172
172
 
173
+ #### Sorting Documents in a Collection
174
+
175
+ To sort documents, simply use the `sort` method. The method can either take a key or an array of [key, direction] pairs to sort by.
176
+
177
+ Direction defaults to ascending order but can be specified as Mongo::ASCENDING, :ascending, or :asc whereas descending order can be specified with Mongo::DESCENDING, :descending, or :desc.
178
+
179
+ # Sort in ascending order by :i
180
+ coll.find.sort(:i)
181
+
182
+ # Sort in descending order by :i
183
+ coll.find.sort([:i, :desc])
184
+
173
185
  #### Counting Documents in a Collection
174
186
 
175
187
  Now that we've inserted 101 documents (the 100 we did in the loop, plus the first one), we can check to see if we have them all using the `count` method.
@@ -9,7 +9,7 @@ Write concern is set using the `:safe` option. There are several possible option
9
9
  @collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200})
10
10
  @collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200, :j => true})
11
11
 
12
- The first, `true`, simply indicates that we should request a response from the server to ensure that to errors have occurred. The second, `{:w => 2}`, forces the server to wait until at least two servers have recorded the write. The third does the same but will time out if the replication can't be completed in 200 milliseconds.
12
+ The first, `true`, simply indicates that we should request a response from the server to ensure that no errors have occurred. The second, `{:w => 2}`, forces the server to wait until at least two servers have recorded the write. The third does the same but will time out if the replication can't be completed in 200 milliseconds.
13
13
  Setting a value for `wtimeout` is encouraged.
14
14
 
15
15
  Finally, the fourth example forces the journal to sync to disk if journaling is enabled.
@@ -184,7 +184,7 @@ module Mongo
184
184
  # end of the query's execution.
185
185
  # For details see http://www.mongodb.org/display/DOCS/How+to+do+Snapshotting+in+the+Mongo+Database
186
186
  # @option opts [Boolean] :batch_size (100) the number of documents to returned by the database per
187
- # GETMORE operation. A value of 0 will let the database server decide how many results to returns.
187
+ # GETMORE operation. A value of 0 will let the database server decide how many results to return.
188
188
  # This option can be ignored for most use cases.
189
189
  # @option opts [Boolean] :timeout (true) when +true+, the returned cursor will be subject to
190
190
  # the normal cursor timeout behavior of the mongod process. When +false+, the returned cursor will
@@ -32,6 +32,7 @@ module Mongo
32
32
 
33
33
  Thread.abort_on_exception = true
34
34
 
35
+ DEFAULT_HOST = 'localhost'
35
36
  DEFAULT_PORT = 27017
36
37
  GENERIC_OPTS = [:ssl, :auths, :pool_size, :pool_timeout, :timeout, :op_timeout, :connect_timeout, :safe, :logger, :connect]
37
38
  CONNECTION_OPTS = [:slave_ok]
@@ -44,6 +45,8 @@ module Mongo
44
45
 
45
46
  # Create a connection to single MongoDB instance.
46
47
  #
48
+ # If no args are provided, it will check <code>ENV["MONGODB_URI"]</code>.
49
+ #
47
50
  # You may specify whether connection to slave is permitted.
48
51
  # In all cases, the default host is "localhost" and the default port is 27017.
49
52
  #
@@ -76,26 +79,39 @@ module Mongo
76
79
  # connection attempt.
77
80
  # @option opts [Boolean] :ssl (false) If true, create the connection to the server using SSL.
78
81
  #
79
- # @example localhost, 27017
80
- # Connection.new
82
+ # @example localhost, 27017 (or <code>ENV["MONGODB_URI"]</code> if available)
83
+ # Mongo::Connection.new
81
84
  #
82
85
  # @example localhost, 27017
83
- # Connection.new("localhost")
86
+ # Mongo::Connection.new("localhost")
84
87
  #
85
88
  # @example localhost, 3000, max 5 self.connections, with max 5 seconds of wait time.
86
- # Connection.new("localhost", 3000, :pool_size => 5, :timeout => 5)
89
+ # Mongo::Connection.new("localhost", 3000, :pool_size => 5, :timeout => 5)
87
90
  #
88
91
  # @example localhost, 3000, where this node may be a slave
89
- # Connection.new("localhost", 3000, :slave_ok => true)
92
+ # Mongo::Connection.new("localhost", 3000, :slave_ok => true)
90
93
  #
91
94
  # @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby
92
95
  #
93
96
  # @raise [ReplicaSetConnectionError] This is raised if a replica set name is specified and the
94
97
  # driver fails to connect to a replica set with that name.
95
98
  #
99
+ # @raise [MongoArgumentError] If called with no arguments and <code>ENV["MONGODB_URI"]</code> implies a replica set.
100
+ #
96
101
  # @core self.connections
97
102
  def initialize(host=nil, port=nil, opts={})
98
- @host_to_try = format_pair(host, port)
103
+ if host.nil? and ENV.has_key?('MONGODB_URI')
104
+ parser = URIParser.new ENV['MONGODB_URI'], opts
105
+ if parser.replicaset?
106
+ raise MongoArgumentError, "Mongo::Connection.new called with no arguments, but ENV['MONGODB_URI'] implies a replica set."
107
+ end
108
+ opts = parser.connection_options
109
+ @host_to_try = [parser.host, parser.port]
110
+ elsif host.is_a?(String)
111
+ @host_to_try = [host, (port || DEFAULT_PORT).to_i]
112
+ else
113
+ @host_to_try = [DEFAULT_HOST, DEFAULT_PORT]
114
+ end
99
115
 
100
116
  # Host and port of current master.
101
117
  @host = @port = nil
@@ -131,10 +147,10 @@ module Mongo
131
147
  # to send reads to.
132
148
  #
133
149
  # @example
134
- # Connection.multi([["db1.example.com", 27017], ["db2.example.com", 27017]])
150
+ # Mongo::Connection.multi([["db1.example.com", 27017], ["db2.example.com", 27017]])
135
151
  #
136
152
  # @example This connection will read from a random secondary node.
137
- # Connection.multi([["db1.example.com", 27017], ["db2.example.com", 27017], ["db3.example.com", 27017]],
153
+ # Mongo::Connection.multi([["db1.example.com", 27017], ["db2.example.com", 27017], ["db3.example.com", 27017]],
138
154
  # :read_secondary => true)
139
155
  #
140
156
  # @return [Mongo::Connection]
@@ -143,11 +159,12 @@ module Mongo
143
159
  def self.multi(nodes, opts={})
144
160
  warn "Connection.multi is now deprecated and will be removed in v2.0. Please use ReplSetConnection.new instead."
145
161
 
146
- nodes << opts
147
- ReplSetConnection.new(*nodes)
162
+ ReplSetConnection.new(*(nodes+[opts]))
148
163
  end
149
164
 
150
- # Initialize a connection to MongoDB using the MongoDB URI spec:
165
+ # Initialize a connection to MongoDB using the MongoDB URI spec.
166
+ #
167
+ # Since Connection.new cannot be used with any <code>ENV["MONGODB_URI"]</code> that has multiple hosts (implying a replicaset), you may use this when the type of your connection varies by environment and should be determined solely from <code>ENV["MONGODB_URI"]</code>.
151
168
  #
152
169
  # @param uri [String]
153
170
  # A string of the format mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]
@@ -155,21 +172,9 @@ module Mongo
155
172
  # @param opts Any of the options available for Connection.new
156
173
  #
157
174
  # @return [Mongo::Connection, Mongo::ReplSetConnection]
158
- def self.from_uri(string, extra_opts={})
159
- uri = URIParser.new(string)
160
- opts = uri.connection_options
161
- opts.merge!(extra_opts)
162
-
163
- if uri.nodes.length == 1
164
- opts.merge!({:auths => uri.auths})
165
- Connection.new(uri.nodes[0][0], uri.nodes[0][1], opts)
166
- elsif uri.nodes.length > 1
167
- nodes = uri.nodes.clone
168
- nodes_with_opts = nodes << opts
169
- ReplSetConnection.new(*nodes_with_opts)
170
- else
171
- raise MongoArgumentError, "No nodes specified. Please ensure that you've provided at least one node."
172
- end
175
+ def self.from_uri(uri = ENV['MONGODB_URI'], extra_opts={})
176
+ parser = URIParser.new uri, extra_opts
177
+ parser.connection
173
178
  end
174
179
 
175
180
  # The host name used for this connection.
@@ -337,7 +342,7 @@ module Mongo
337
342
  # @param [String] from_host host of the 'from' database.
338
343
  # @param [String] username username for authentication against from_db (>=1.3.x).
339
344
  # @param [String] password password for authentication against from_db (>=1.3.x).
340
- def copy_database(from, to, from_host="localhost", username=nil, password=nil)
345
+ def copy_database(from, to, from_host=DEFAULT_HOST, username=nil, password=nil)
341
346
  oh = BSON::OrderedHash.new
342
347
  oh[:copydb] = 1
343
348
  oh[:fromhost] = from_host
@@ -585,23 +590,8 @@ module Mongo
585
590
  write_logging_startup_message
586
591
  end
587
592
 
588
- should_connect = opts.fetch(:connect, true)
589
- connect if should_connect
590
- end
591
-
592
- ## Configuration helper methods
593
-
594
- # Returns a host-port pair.
595
- #
596
- # @return [Array]
597
- #
598
- # @private
599
- def format_pair(host, port)
600
- case host
601
- when String
602
- [host, port ? port.to_i : DEFAULT_PORT]
603
- when nil
604
- ['localhost', DEFAULT_PORT]
593
+ if opts.fetch(:connect, true)
594
+ connect
605
595
  end
606
596
  end
607
597
 
@@ -622,9 +612,7 @@ module Mongo
622
612
  socket = nil
623
613
  config = nil
624
614
 
625
- socket = @socket_class.new(host, port, @op_timeout, @connect_timeout)
626
- socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
627
-
615
+ socket = @socket_class.new(host, port, @op_timeout, @connect_timeout)
628
616
  config = self['admin'].command({:ismaster => 1}, :socket => socket)
629
617
  rescue OperationFailure, SocketError, SystemCallError, IOError
630
618
  close
@@ -199,21 +199,19 @@ module Mongo
199
199
  # This method overrides any sort order specified in the Collection#find
200
200
  # method, and only the last sort applied has an effect.
201
201
  #
202
- # @param [Symbol, Array] key_or_list either 1) a key to sort by or 2)
203
- # an array of [key, direction] pairs to sort by. Direction should
204
- # be specified as Mongo::ASCENDING (or :ascending / :asc) or Mongo::DESCENDING (or :descending / :desc)
202
+ # @param [Symbol, Array] key_or_list either 1) a key to sort by 2)
203
+ # an array of [key, direction] pairs to sort by or 3) a hash of
204
+ # field => direction pairs to sort by. Direction should be specified as
205
+ # Mongo::ASCENDING (or :ascending / :asc) or Mongo::DESCENDING
206
+ # (or :descending / :desc)
205
207
  #
206
208
  # @raise [InvalidOperation] if this cursor has already been used.
207
209
  #
208
210
  # @raise [InvalidSortValueError] if the specified order is invalid.
209
- def sort(key_or_list, direction=nil)
211
+ def sort(order, direction=nil)
210
212
  check_modifiable
211
213
 
212
- if !direction.nil?
213
- order = [[key_or_list, direction]]
214
- else
215
- order = key_or_list
216
- end
214
+ order = [[order, direction]] unless direction.nil?
217
215
 
218
216
  @order = order
219
217
  self
@@ -258,6 +256,9 @@ module Mongo
258
256
  #
259
257
  # Note that the batch size will take effect only on queries
260
258
  # where the number to be returned is greater than 100.
259
+ #
260
+ # This can not override MongoDB's limit on the amount of data it will
261
+ # return to the client. Depending on server version this can be 4-16mb.
261
262
  #
262
263
  # @param [Integer] size either 0 or some integer greater than 1. If 0,
263
264
  # the server will determine the batch size.
@@ -438,7 +438,7 @@ module Mongo
438
438
  #
439
439
  # @return [True] returns +true+ on success.
440
440
  #
441
- # @raise MongoDBError if there's an error renaming the collection.
441
+ # @raise MongoDBError if there's an error dropping the index.
442
442
  def drop_index(collection_name, index_name)
443
443
  oh = BSON::OrderedHash.new
444
444
  oh[:deleteIndexes] = collection_name