mongo 1.8.6 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +13 -1
  5. data/VERSION +1 -1
  6. data/bin/mongo_console +15 -0
  7. data/lib/mongo.rb +14 -0
  8. data/lib/mongo/collection.rb +80 -42
  9. data/lib/mongo/cursor.rb +15 -1
  10. data/lib/mongo/db.rb +56 -19
  11. data/lib/mongo/exceptions.rb +14 -0
  12. data/lib/mongo/gridfs/grid.rb +16 -3
  13. data/lib/mongo/gridfs/grid_ext.rb +14 -0
  14. data/lib/mongo/gridfs/grid_file_system.rb +16 -3
  15. data/lib/mongo/gridfs/grid_io.rb +17 -3
  16. data/lib/mongo/legacy.rb +14 -0
  17. data/lib/mongo/mongo_client.rb +93 -40
  18. data/lib/mongo/mongo_replica_set_client.rb +21 -0
  19. data/lib/mongo/mongo_sharded_client.rb +15 -1
  20. data/lib/mongo/networking.rb +14 -0
  21. data/lib/mongo/util/conversions.rb +16 -2
  22. data/lib/mongo/util/core_ext.rb +14 -31
  23. data/lib/mongo/util/logging.rb +23 -7
  24. data/lib/mongo/util/node.rb +17 -2
  25. data/lib/mongo/util/pool.rb +17 -1
  26. data/lib/mongo/util/pool_manager.rb +15 -2
  27. data/lib/mongo/util/read_preference.rb +14 -0
  28. data/lib/mongo/util/server_version.rb +15 -0
  29. data/lib/mongo/util/sharding_pool_manager.rb +13 -0
  30. data/lib/mongo/util/socket_util.rb +14 -0
  31. data/lib/mongo/util/ssl_socket.rb +48 -7
  32. data/lib/mongo/util/support.rb +14 -0
  33. data/lib/mongo/util/tcp_socket.rb +18 -4
  34. data/lib/mongo/util/thread_local_variable_manager.rb +14 -0
  35. data/lib/mongo/util/unix_socket.rb +20 -6
  36. data/lib/mongo/util/uri_parser.rb +16 -8
  37. data/lib/mongo/util/write_concern.rb +16 -2
  38. data/test/functional/authentication_test.rb +26 -1
  39. data/test/functional/collection_test.rb +140 -41
  40. data/test/functional/connection_test.rb +19 -6
  41. data/test/functional/conversions_test.rb +14 -0
  42. data/test/functional/cursor_fail_test.rb +14 -0
  43. data/test/functional/cursor_message_test.rb +14 -0
  44. data/test/functional/cursor_test.rb +15 -1
  45. data/test/functional/db_api_test.rb +15 -1
  46. data/test/functional/db_connection_test.rb +14 -0
  47. data/test/functional/db_test.rb +14 -0
  48. data/test/functional/grid_file_system_test.rb +16 -4
  49. data/test/functional/grid_io_test.rb +14 -0
  50. data/test/functional/grid_test.rb +14 -0
  51. data/test/functional/pool_test.rb +22 -6
  52. data/test/functional/safe_test.rb +14 -0
  53. data/test/functional/ssl_test.rb +109 -0
  54. data/test/functional/support_test.rb +14 -0
  55. data/test/functional/threading_test.rb +22 -8
  56. data/test/functional/timeout_test.rb +20 -6
  57. data/test/functional/uri_test.rb +14 -14
  58. data/test/functional/write_concern_test.rb +14 -0
  59. data/test/replica_set/authentication_test.rb +28 -2
  60. data/test/replica_set/basic_test.rb +14 -0
  61. data/test/replica_set/client_test.rb +14 -0
  62. data/test/replica_set/complex_connect_test.rb +14 -0
  63. data/test/replica_set/connection_test.rb +14 -0
  64. data/test/replica_set/count_test.rb +14 -0
  65. data/test/replica_set/cursor_test.rb +14 -0
  66. data/test/replica_set/insert_test.rb +14 -0
  67. data/test/replica_set/max_values_test.rb +14 -0
  68. data/test/replica_set/pinning_test.rb +14 -0
  69. data/test/replica_set/query_test.rb +14 -0
  70. data/test/replica_set/read_preference_test.rb +14 -0
  71. data/test/replica_set/refresh_test.rb +14 -0
  72. data/test/replica_set/replication_ack_test.rb +14 -0
  73. data/test/replica_set/ssl_test.rb +114 -0
  74. data/test/sharded_cluster/basic_test.rb +14 -0
  75. data/test/shared/authentication.rb +55 -0
  76. data/test/test_helper.rb +15 -1
  77. data/test/threading/basic_test.rb +14 -0
  78. data/test/tools/mongo_config.rb +16 -1
  79. data/test/tools/mongo_config_test.rb +15 -1
  80. data/test/unit/client_test.rb +14 -0
  81. data/test/unit/collection_test.rb +14 -0
  82. data/test/unit/connection_test.rb +14 -0
  83. data/test/unit/cursor_test.rb +14 -0
  84. data/test/unit/db_test.rb +15 -1
  85. data/test/unit/grid_test.rb +14 -0
  86. data/test/unit/mongo_sharded_client_test.rb +14 -0
  87. data/test/unit/node_test.rb +15 -0
  88. data/test/unit/pool_manager_test.rb +15 -0
  89. data/test/unit/pool_test.rb +14 -0
  90. data/test/unit/read_pref_test.rb +14 -0
  91. data/test/unit/read_test.rb +14 -0
  92. data/test/unit/safe_test.rb +14 -0
  93. data/test/unit/sharding_pool_manager_test.rb +15 -0
  94. data/test/unit/util_test.rb +14 -0
  95. data/test/unit/write_concern_test.rb +15 -1
  96. metadata +8 -4
  97. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bdb78ad2291ea3ecb387526ccdbd162ffd51687
4
- data.tar.gz: 6b3ec42fadc3f0beea953a08fe07a2d2ff206cba
3
+ metadata.gz: 7f7fb956c60cb3b6d5b8388b45c3b03596d42215
4
+ data.tar.gz: 42c3a9fdf43eaf64304bd119a5f0aa07957b7ada
5
5
  SHA512:
6
- metadata.gz: 83bb86f711779590a47d0d8d83fea4d844cd8ebdcde6617109c9172dd9d6961688d3faf03c1c7d0c0601575ed1a253522aecc2b26f2e81fb7980079ca3dff9fd
7
- data.tar.gz: 880a70826f29e9e60fff3d26ede30390da593e78ad095f635743ffec711ce22af34da2d89318fd48f7825e2583bbec02da80c78899d4388386a76c769ee1e80e
6
+ metadata.gz: 08c9bcfd41885ddfebffbf0bf3bed97298e5a17751ab67aeb1e15a1c2639d5bc7830efe319c9d4873793b86cc7aeb62523f8e2e8f6f52c7158dcb908581ab9a9
7
+ data.tar.gz: 4dd3325d16fd0729c9943b79eefb7f88a72818ac67a6a9822bc802fdba8b804fec651ea9ea54d614d32cb390a3cdf543e30492f0a29b43ab8b307c9ab02bece9
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -1,4 +1,16 @@
1
- # -*- mode: ruby; -*-
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
2
14
 
3
15
  require 'rubygems'
4
16
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.6
1
+ 1.9.0
@@ -1,4 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
+
3
+ # Copyright (C) 2013 10gen Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
2
17
  org_argv = ARGV.dup
3
18
  ARGV.clear
4
19
 
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
  ASCENDING = 1
3
17
  DESCENDING = -1
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
 
3
17
  # A named collection of documents in a database.
@@ -1066,43 +1080,32 @@ module Mongo
1066
1080
  nil
1067
1081
  end
1068
1082
 
1069
- # Sends a Mongo::Constants::OP_INSERT message to the database.
1070
- # Takes an array of +documents+, an optional +collection_name+, and a
1071
- # +check_keys+ setting.
1072
- def insert_documents(documents, collection_name=@name, check_keys=true, write_concern={}, flags={})
1073
- message = BSON::ByteBuffer.new("", @connection.max_message_size)
1074
- if flags[:continue_on_error]
1075
- message.put_int(1)
1076
- else
1077
- message.put_int(0)
1083
+ def generate_index_name(spec)
1084
+ indexes = []
1085
+ spec.each_pair do |field, type|
1086
+ indexes.push("#{field}_#{type}")
1078
1087
  end
1088
+ indexes.join("_")
1089
+ end
1079
1090
 
1080
- collect_on_error = !!flags[:collect_on_error]
1081
- error_docs = [] if collect_on_error
1082
-
1091
+ def insert_buffer(collection_name, continue_on_error)
1092
+ message = BSON::ByteBuffer.new("", @connection.max_message_size)
1093
+ message.put_int(continue_on_error ? 1 : 0)
1083
1094
  BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{collection_name}")
1084
- documents =
1085
- if collect_on_error
1086
- documents.select do |doc|
1087
- begin
1088
- message.put_binary(BSON::BSON_CODER.serialize(doc, check_keys, true, @connection.max_bson_size).to_s)
1089
- true
1090
- rescue StandardError # StandardError will be replaced with BSONError
1091
- doc.delete(:_id)
1092
- error_docs << doc
1093
- false
1094
- end
1095
- end
1096
- else
1097
- documents.each do |doc|
1098
- message.put_binary(BSON::BSON_CODER.serialize(doc, check_keys, true, @connection.max_bson_size).to_s)
1099
- end
1100
- end
1095
+ message
1096
+ end
1101
1097
 
1102
- if message.size > @connection.max_message_size
1103
- raise InvalidOperation, "Exceded maximum insert size of #{@connection.max_message_size} bytes"
1098
+ def insert_batch(message, documents, write_concern, continue_on_error, errors, collection_name=@name)
1099
+ begin
1100
+ send_insert_message(message, documents, collection_name, write_concern)
1101
+ rescue ConnectionFailure, OperationFailure, OperationTimeout, SystemStackError,
1102
+ NoMemoryError, SystemCallError => ex
1103
+ raise ex unless continue_on_error
1104
+ errors << ex
1104
1105
  end
1106
+ end
1105
1107
 
1108
+ def send_insert_message(message, documents, collection_name, write_concern)
1106
1109
  instrument(:insert, :database => @db.name, :collection => collection_name, :documents => documents) do
1107
1110
  if Mongo::WriteConcern.gle?(write_concern)
1108
1111
  @connection.send_message_with_gle(Mongo::Constants::OP_INSERT, message, @db.name, nil, write_concern)
@@ -1110,21 +1113,56 @@ module Mongo
1110
1113
  @connection.send_message(Mongo::Constants::OP_INSERT, message)
1111
1114
  end
1112
1115
  end
1116
+ end
1113
1117
 
1114
- doc_ids = documents.collect { |o| o[:_id] || o['_id'] }
1115
- if collect_on_error
1116
- return doc_ids, error_docs
1117
- else
1118
- doc_ids
1118
+ # Sends a Mongo::Constants::OP_INSERT message to the database.
1119
+ # Takes an array of +documents+, an optional +collection_name+, and a
1120
+ # +check_keys+ setting.
1121
+ def insert_documents(documents, collection_name=@name, check_keys=true, write_concern={}, flags={})
1122
+ continue_on_error = !!flags[:continue_on_error]
1123
+ collect_on_error = !!flags[:collect_on_error]
1124
+ error_docs = [] # docs with errors on serialization
1125
+ errors = [] # for all errors on insertion
1126
+ batch_start = 0
1127
+
1128
+ message = insert_buffer(collection_name, continue_on_error)
1129
+
1130
+ documents.each_with_index do |doc, index|
1131
+ begin
1132
+ serialized_doc = BSON::BSON_CODER.serialize(doc, check_keys, true, @connection.max_bson_size)
1133
+ rescue BSON::InvalidDocument, BSON::InvalidKeyName, BSON::InvalidStringEncoding => ex
1134
+ raise ex unless collect_on_error
1135
+ error_docs << doc
1136
+ next
1137
+ end
1138
+
1139
+ # Check if the current msg has room for this doc. If not, send current msg and create a new one.
1140
+ # GLE is a sep msg with its own header so shouldn't be included in padding with header size.
1141
+ total_message_size = Networking::STANDARD_HEADER_SIZE + message.size + serialized_doc.size
1142
+ if total_message_size > @connection.max_message_size
1143
+ docs_to_insert = documents[batch_start..index] - error_docs
1144
+ insert_batch(message, docs_to_insert, write_concern, continue_on_error, errors, collection_name)
1145
+ batch_start = index
1146
+ message = insert_buffer(collection_name, continue_on_error)
1147
+ redo
1148
+ else
1149
+ message.put_binary(serialized_doc.to_s)
1150
+ end
1119
1151
  end
1120
- end
1121
1152
 
1122
- def generate_index_name(spec)
1123
- indexes = []
1124
- spec.each_pair do |field, type|
1125
- indexes.push("#{field}_#{type}")
1153
+ docs_to_insert = documents[batch_start..-1] - error_docs
1154
+ inserted_docs = documents - error_docs
1155
+ inserted_ids = inserted_docs.collect {|o| o[:_id] || o['_id']}
1156
+
1157
+ # Avoid insertion if all docs failed serialization and collect_on_error
1158
+ if error_docs.empty? || !docs_to_insert.empty?
1159
+ insert_batch(message, docs_to_insert, write_concern, continue_on_error, errors, collection_name)
1160
+ # insert_batch collects errors if w > 0 and continue_on_error is true,
1161
+ # so raise the error here, as this is the last or only msg sent
1162
+ raise errors.first unless errors.empty?
1126
1163
  end
1127
- indexes.join("_")
1164
+
1165
+ collect_on_error ? [inserted_ids, error_docs] : inserted_ids
1128
1166
  end
1129
1167
  end
1130
1168
 
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
 
3
17
  # A cursor over query results. Returned objects are hashes.
@@ -424,7 +438,7 @@ module Mongo
424
438
  {fields => 1}
425
439
  when Array
426
440
  return nil if fields.length.zero?
427
- fields.each_with_object({}) { |field, hash| hash[field] = 1 }
441
+ fields.inject({}) { |hash, field| hash[field] = 1; hash }
428
442
  when Hash
429
443
  return fields
430
444
  end
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'socket'
2
16
  require 'thread'
3
17
 
@@ -109,27 +123,35 @@ module Mongo
109
123
  # @param [String] password
110
124
  # @param [Boolean] save_auth
111
125
  # Save this authentication to the client object using MongoClient#add_auth. This
112
- # will ensure that the authentication will be applied on database reconnect. Note
113
- # that this value must be true when using connection pooling.
126
+ # will ensure that the authentication will be applied to all sockets and upon
127
+ # database reconnect.
128
+ # @param source [String] Database with user credentials. This should be used to
129
+ # authenticate against a database when the credentials exist elsewhere.
130
+ #
131
+ # @note save_auth must be true when using connection pooling or providing a source
132
+ # for credentials.
114
133
  #
115
134
  # @return [Boolean]
116
135
  #
117
136
  # @raise [AuthenticationError]
118
137
  #
119
138
  # @core authenticate authenticate-instance_method
120
- def authenticate(username, password, save_auth=true)
121
- if @connection.pool_size > 1 && !save_auth
122
- raise MongoArgumentError, "If using connection pooling, :save_auth must be set to true."
139
+ def authenticate(username, password=nil, save_auth=true, source=nil)
140
+ if (@connection.pool_size > 1 || source) && !save_auth
141
+ raise MongoArgumentError, "If using connection pooling or delegated auth, " +
142
+ ":save_auth must be set to true."
123
143
  end
124
144
 
125
145
  begin
126
146
  socket = @connection.checkout_reader(:mode => :primary_preferred)
127
- issue_authentication(username, password, save_auth, :socket => socket)
147
+ issue_authentication(username, password, save_auth,
148
+ :socket => socket, :source => source)
128
149
  ensure
129
150
  socket.checkin if socket
130
151
  end
131
152
 
132
153
  @connection.authenticate_pools
154
+ true
133
155
  end
134
156
 
135
157
  def issue_authentication(username, password, save_auth=true, opts={})
@@ -137,15 +159,19 @@ module Mongo
137
159
  raise MongoDBError, "Error retrieving nonce: #{doc}" unless ok?(doc)
138
160
  nonce = doc['nonce']
139
161
 
162
+ # issue authentication against this database if source option not provided
163
+ source = opts[:source]
164
+ db = source ? @connection[source] : self
165
+
140
166
  auth = BSON::OrderedHash.new
141
167
  auth['authenticate'] = 1
142
168
  auth['user'] = username
143
169
  auth['nonce'] = nonce
144
170
  auth['key'] = Mongo::Support.auth_key(username, password, nonce)
145
- if ok?(doc = self.command(auth, :check_response => false, :socket => opts[:socket]))
146
- @connection.add_auth(@name, username, password) if save_auth
171
+ if ok?(doc = db.command(auth, :check_response => false, :socket => opts[:socket]))
172
+ @connection.add_auth(name, username, password, source) if save_auth
147
173
  else
148
- message = "Failed to authenticate user '#{username}' on db '#{self.name}'"
174
+ message = "Failed to authenticate user '#{username}' on db '#{db.name}'"
149
175
  raise Mongo::AuthenticationError.new(message, doc['code'], doc)
150
176
  end
151
177
  true
@@ -179,19 +205,30 @@ module Mongo
179
205
  end
180
206
 
181
207
  # Adds a user to this database for use with authentication. If the user already
182
- # exists in the system, the password will be updated.
208
+ # exists in the system, the password and any additional fields provided in opts
209
+ # will be updated.
183
210
  #
184
211
  # @param [String] username
185
212
  # @param [String] password
186
213
  # @param [Boolean] read_only
187
214
  # Create a read-only user.
188
215
  #
216
+ # @param [Hash] opts
217
+ # Optional fields for the user document (e.g. +userSource+, or +roles+)
218
+ #
219
+ # See {http://docs.mongodb.org/manual/reference/privilege-documents}
220
+ # for more information.
221
+ #
222
+ # @note The use of the opts argument to provide or update additional fields
223
+ # on the user document requires MongoDB >= 2.4.0
224
+ #
189
225
  # @return [Hash] an object representing the user.
190
- def add_user(username, password, read_only = false)
226
+ def add_user(username, password=nil, read_only=false, opts={})
191
227
  users = self[SYSTEM_USER_COLLECTION]
192
228
  user = users.find_one({:user => username}) || {:user => username}
193
- user['pwd'] = Mongo::Support.hash_password(username, password)
194
- user['readOnly'] = true if read_only;
229
+ user['pwd'] = Mongo::Support.hash_password(username, password) if password
230
+ user['readOnly'] = true if read_only
231
+ user.merge!(opts)
195
232
  begin
196
233
  users.save(user)
197
234
  rescue OperationFailure => ex
@@ -223,14 +260,14 @@ module Mongo
223
260
  #
224
261
  # @return [Boolean]
225
262
  def logout(opts={})
226
- @connection.logout_pools(@name) if @connection.pool_size > 1
227
- issue_logout(opts)
263
+ auth = @connection.auths.find { |a| a[:db_name] == name }
264
+ db = auth && auth[:source] ? @connection[auth[:source]] : self
265
+ auth ? @connection.logout_pools(db.name) : db.issue_logout(opts)
266
+ @connection.remove_auth(db.name)
228
267
  end
229
268
 
230
269
  def issue_logout(opts={})
231
- if ok?(doc = command({:logout => 1}, :socket => opts[:socket]))
232
- @connection.remove_auth(@name)
233
- else
270
+ unless ok?(doc = command({:logout => 1}, :socket => opts[:socket]))
234
271
  raise MongoDBError, "Error logging out: #{doc.inspect}"
235
272
  end
236
273
  true
@@ -336,7 +373,7 @@ module Mongo
336
373
  return false if strict? && !collection_names.include?(name.to_s)
337
374
  begin
338
375
  ok?(command(:drop => name))
339
- rescue OperationFailure => e
376
+ rescue OperationFailure
340
377
  false
341
378
  end
342
379
  end
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
  # Generic Mongo Ruby Driver exception class.
3
17
  class MongoRubyError < StandardError; end
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
 
3
17
  # Implementation of the MongoDB GridFS specification. A file store.
@@ -21,7 +35,6 @@ module Mongo
21
35
  @fs_name = fs_name
22
36
 
23
37
  # This will create indexes only if we're connected to a primary node.
24
- connection = @db.connection
25
38
  begin
26
39
  @chunks.ensure_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
27
40
  rescue Mongo::ConnectionFailure
@@ -46,8 +59,8 @@ module Mongo
46
59
  # @option opts [Integer] (262144) :chunk_size size of file chunks in bytes.
47
60
  # @option opts [String, Integer, Symbol] :w (1) Set write concern
48
61
  #
49
- # Notes on write concern:
50
- # When :w > 0, the chunks sent to the server are validated using an md5 hash.
62
+ # Notes on write concern:
63
+ # When :w > 0, the chunks sent to the server are validated using an md5 hash.
51
64
  # If validation fails, an exception will be raised.
52
65
  #
53
66
  # @return [BSON::ObjectId] the file's id.