mongo 1.10.0.rc1 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +5 -0
- data/VERSION +1 -1
- data/lib/mongo.rb +1 -0
- data/lib/mongo/bulk_write_collection_view.rb +12 -12
- data/lib/mongo/collection.rb +3 -2
- data/lib/mongo/collection_writer.rb +20 -5
- data/lib/mongo/connection/pool_manager.rb +41 -5
- data/lib/mongo/connection/socket/ssl_socket.rb +5 -1
- data/lib/mongo/cursor.rb +3 -3
- data/lib/mongo/db.rb +1 -1
- data/lib/mongo/exception.rb +3 -0
- data/lib/mongo/functional/authentication.rb +1 -1
- data/lib/mongo/functional/sasl_java.rb +1 -1
- data/lib/mongo/functional/uri_parser.rb +4 -6
- data/lib/mongo/functional/write_concern.rb +4 -7
- data/lib/mongo/gridfs/grid.rb +3 -3
- data/lib/mongo/gridfs/grid_file_system.rb +1 -1
- data/lib/mongo/gridfs/grid_io.rb +4 -6
- data/lib/mongo/mongo_client.rb +19 -11
- data/lib/mongo/mongo_replica_set_client.rb +1 -1
- data/lib/mongo/mongo_sharded_client.rb +2 -2
- data/lib/mongo/networking.rb +13 -9
- data/test/functional/client_test.rb +14 -0
- data/test/functional/collection_test.rb +70 -100
- data/test/functional/grid_io_test.rb +2 -2
- data/test/functional/grid_test.rb +1 -1
- data/test/replica_set/insert_test.rb +15 -1
- data/test/replica_set/replication_ack_test.rb +11 -5
- data/test/shared/ssl_shared.rb +44 -4
- data/test/unit/pool_manager_test.rb +31 -0
- metadata +6 -6
- metadata.gz.sig +0 -0
@@ -60,7 +60,7 @@ module Mongo
|
|
60
60
|
# @option opts [String] :content_type ('binary/octet-stream') If no content type is specified,
|
61
61
|
# the content type will may be inferred from the filename extension if the mime-types gem can be
|
62
62
|
# loaded. Otherwise, the content type 'binary/octet-stream' will be used.
|
63
|
-
# @option opts [Integer] (
|
63
|
+
# @option opts [Integer] (261120) :chunk_size size of file chunks in bytes.
|
64
64
|
# @option opts [Boolean] :delete_old (false) ensure that old versions of the file are deleted. This option
|
65
65
|
# only work in 'w' mode. Certain precautions must be taken when deleting GridFS files. See the notes under
|
66
66
|
# GridFileSystem#delete.
|
data/lib/mongo/gridfs/grid_io.rb
CHANGED
@@ -21,7 +21,7 @@ module Mongo
|
|
21
21
|
class GridIO
|
22
22
|
include Mongo::WriteConcern
|
23
23
|
|
24
|
-
DEFAULT_CHUNK_SIZE =
|
24
|
+
DEFAULT_CHUNK_SIZE = 255 * 1024
|
25
25
|
DEFAULT_CONTENT_TYPE = 'binary/octet-stream'
|
26
26
|
PROTECTED_ATTRS = [:files_id, :file_length, :client_md5, :server_md5]
|
27
27
|
|
@@ -39,7 +39,7 @@ module Mongo
|
|
39
39
|
# @option opts [Hash] :query a query selector used when opening the file in 'r' mode.
|
40
40
|
# @option opts [Hash] :query_opts any query options to be used when opening the file in 'r' mode.
|
41
41
|
# @option opts [String] :fs_name the file system prefix.
|
42
|
-
# @option opts [Integer] (
|
42
|
+
# @option opts [Integer] (261120) :chunk_size size of file chunks in bytes.
|
43
43
|
# @option opts [Hash] :metadata ({}) any additional data to store with the file.
|
44
44
|
# @option opts [ObjectId] :_id (ObjectId) a unique id for
|
45
45
|
# the file to be use in lieu of an automatically generated one.
|
@@ -106,11 +106,9 @@ module Mongo
|
|
106
106
|
|
107
107
|
# Write the given string (binary) data to the file.
|
108
108
|
#
|
109
|
-
# @param [String]
|
110
|
-
# the data to write
|
109
|
+
# @param [String] io the data to write.
|
111
110
|
#
|
112
|
-
# @return [Integer]
|
113
|
-
# the number of bytes written.
|
111
|
+
# @return [Integer] the number of bytes written.
|
114
112
|
def write(io)
|
115
113
|
raise GridError, "file not opened for write" unless @mode[0] == ?w
|
116
114
|
if io.is_a? String
|
data/lib/mongo/mongo_client.rb
CHANGED
@@ -43,7 +43,7 @@ module Mongo
|
|
43
43
|
DEFAULT_DB_NAME = 'test'
|
44
44
|
GENERIC_OPTS = [:auths, :logger, :connect, :db_name]
|
45
45
|
TIMEOUT_OPTS = [:timeout, :op_timeout, :connect_timeout]
|
46
|
-
SSL_OPTS = [:ssl, :ssl_key, :ssl_cert, :ssl_verify, :ssl_ca_cert]
|
46
|
+
SSL_OPTS = [:ssl, :ssl_key, :ssl_cert, :ssl_verify, :ssl_ca_cert, :ssl_key_pass_phrase]
|
47
47
|
POOL_OPTS = [:pool_size, :pool_timeout]
|
48
48
|
READ_PREFERENCE_OPTS = [:read, :tag_sets, :secondary_acceptable_latency_ms]
|
49
49
|
WRITE_CONCERN_OPTS = [:w, :j, :fsync, :wtimeout]
|
@@ -90,14 +90,14 @@ module Mongo
|
|
90
90
|
# @param [Integer] port specify a port number here if only one host is being specified.
|
91
91
|
# @param [Hash] opts hash of optional settings and configuration values.
|
92
92
|
#
|
93
|
-
#
|
93
|
+
# @option opts [String, Integer, Symbol] :w (1) Set default number of nodes to which a write
|
94
94
|
# should be acknowledged.
|
95
|
-
#
|
96
|
-
#
|
95
|
+
# @option opts [Integer] :wtimeout (nil) Set replica set acknowledgement timeout.
|
96
|
+
# @option opts [Boolean] :j (false) If true, block until write operations have been committed
|
97
97
|
# to the journal. Cannot be used in combination with 'fsync'. Prior to MongoDB 2.6 this option was
|
98
98
|
# ignored if the server was running without journaling. Starting with MongoDB 2.6, write operations will
|
99
99
|
# fail with an exception if this option is used when the server is running without journaling.
|
100
|
-
#
|
100
|
+
# @option opts [Boolean] :fsync (false) If true, and the server is running without journaling, blocks until
|
101
101
|
# the server has synced all data files to disk. If the server is running with journaling, this acts the same as
|
102
102
|
# the 'j' option, blocking until write operations have been committed to the journal.
|
103
103
|
# Cannot be used in combination with 'j'.
|
@@ -111,7 +111,7 @@ module Mongo
|
|
111
111
|
# @option opts [String] :ssl_cert (nil) The certificate file used to identify the local connection against MongoDB.
|
112
112
|
# @option opts [String] :ssl_key (nil) The private keyfile used to identify the local connection against MongoDB.
|
113
113
|
# Note that even if the key is stored in the same file as the certificate, both need to be explicitly specified.
|
114
|
-
#
|
114
|
+
# @option opts [String] :ssl_key_pass_phrase (nil) A passphrase for the private key.
|
115
115
|
# @option opts [Boolean] :ssl_verify (nil) Specifies whether or not peer certification validation should occur.
|
116
116
|
# @option opts [String] :ssl_ca_cert (nil) The ca_certs file contains a set of concatenated "certification authority"
|
117
117
|
# certificates, which are used to validate certificates passed from the other end of the connection.
|
@@ -216,7 +216,7 @@ module Mongo
|
|
216
216
|
# @param uri [String]
|
217
217
|
# A string of the format mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]
|
218
218
|
#
|
219
|
-
# @param
|
219
|
+
# @param [Hash] extra_opts Any of the options available for MongoClient.new
|
220
220
|
#
|
221
221
|
# @return [Mongo::MongoClient, Mongo::MongoReplicaSetClient]
|
222
222
|
def self.from_uri(uri = ENV['MONGODB_URI'], extra_opts={})
|
@@ -594,10 +594,11 @@ module Mongo
|
|
594
594
|
@socket_opts = {}
|
595
595
|
if @ssl
|
596
596
|
# construct ssl socket opts
|
597
|
-
@socket_opts[:key]
|
598
|
-
@socket_opts[:cert]
|
599
|
-
@socket_opts[:verify]
|
600
|
-
@socket_opts[:ca_cert]
|
597
|
+
@socket_opts[:key] = opts.delete(:ssl_key)
|
598
|
+
@socket_opts[:cert] = opts.delete(:ssl_cert)
|
599
|
+
@socket_opts[:verify] = opts.delete(:ssl_verify)
|
600
|
+
@socket_opts[:ca_cert] = opts.delete(:ssl_ca_cert)
|
601
|
+
@socket_opts[:key_pass_phrase] = opts.delete(:ssl_key_pass_phrase)
|
601
602
|
|
602
603
|
# verify peer requires ca_cert, raise if only one is present
|
603
604
|
if @socket_opts[:verify] && !@socket_opts[:ca_cert]
|
@@ -606,6 +607,13 @@ module Mongo
|
|
606
607
|
':ssl_ca_cert in order to perform server validation.'
|
607
608
|
end
|
608
609
|
|
610
|
+
# if we have a keyfile passphrase but no key file, raise
|
611
|
+
if @socket_opts[:key_pass_phrase] && !@socket_opts[:key]
|
612
|
+
raise MongoArgumentError,
|
613
|
+
'If :ssl_key_pass_phrase has been specified, then you must include ' +
|
614
|
+
':ssl_key, the passphrase-protected keyfile.'
|
615
|
+
end
|
616
|
+
|
609
617
|
@socket_class = Mongo::SSLSocket
|
610
618
|
elsif @unix
|
611
619
|
@socket_class = Mongo::UNIXSocket
|
@@ -92,7 +92,7 @@ module Mongo
|
|
92
92
|
# @option opts [String] :ssl_cert (nil) The certificate file used to identify the local connection against MongoDB.
|
93
93
|
# @option opts [String] :ssl_key (nil) The private keyfile used to identify the local connection against MongoDB.
|
94
94
|
# Note that even if the key is stored in the same file as the certificate, both need to be explicitly specified.
|
95
|
-
#
|
95
|
+
# @option opts [String] :ssl_key_pass_phrase (nil) A passphrase for the private key.
|
96
96
|
# @option opts [Boolean] :ssl_verify (nil) Specifies whether or not peer certification validation should occur.
|
97
97
|
# @option opts [String] :ssl_ca_cert (nil) The ca_certs file contains a set of concatenated "certification authority"
|
98
98
|
# certificates, which are used to validate certificates passed from the other end of the connection.
|
@@ -148,10 +148,10 @@ module Mongo
|
|
148
148
|
# @param uri [ String ] string of the format:
|
149
149
|
# mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]
|
150
150
|
#
|
151
|
-
# @param
|
151
|
+
# @param options [ Hash ] Any of the options available for MongoShardedClient.new
|
152
152
|
#
|
153
153
|
# @return [ Mongo::MongoShardedClient ] The sharded client.
|
154
|
-
def self.from_uri(uri, options
|
154
|
+
def self.from_uri(uri, options={})
|
155
155
|
uri ||= ENV['MONGODB_URI']
|
156
156
|
URIParser.new(uri).connection(options, false, true)
|
157
157
|
end
|
data/lib/mongo/networking.rb
CHANGED
@@ -67,8 +67,8 @@ module Mongo
|
|
67
67
|
# @param [Integer] operation a MongoDB opcode.
|
68
68
|
# @param [BSON::ByteBuffer] message a message to send to the database.
|
69
69
|
# @param [String] db_name the name of the database. used on call to get_last_error.
|
70
|
-
# @param [
|
71
|
-
#
|
70
|
+
# @param [String] log_message this is currently a no-op and will be removed.
|
71
|
+
# @param [Hash] write_concern write concern.
|
72
72
|
#
|
73
73
|
# @see DB#get_last_error for valid last error params.
|
74
74
|
#
|
@@ -95,18 +95,20 @@ module Mongo
|
|
95
95
|
raise ex
|
96
96
|
end
|
97
97
|
|
98
|
-
if num_received == 1
|
99
|
-
|
98
|
+
if num_received == 1
|
99
|
+
error = docs[0]['err'] || docs[0]['errmsg']
|
100
|
+
if error && error.include?("not master")
|
100
101
|
close
|
101
102
|
raise ConnectionFailure.new(docs[0]['code'].to_s + ': ' + error, docs[0]['code'], docs[0])
|
102
|
-
|
103
|
+
elsif (note = docs[0]['jnote'] || docs[0]['wnote']) # assignment
|
104
|
+
code = docs[0]['code'] || Mongo::ErrorCode::BAD_VALUE # as of server version 2.5.5
|
105
|
+
raise WriteConcernError.new(code.to_s + ': ' + note, code, docs[0])
|
106
|
+
elsif error
|
103
107
|
code = docs[0]['code'] || Mongo::ErrorCode::UNKNOWN_ERROR
|
104
108
|
error = "wtimeout" if error == "timeout"
|
109
|
+
raise WriteConcernError.new(code.to_s + ': ' + error, code, docs[0]) if error == "wtimeout"
|
105
110
|
raise OperationFailure.new(code.to_s + ': ' + error, code, docs[0])
|
106
111
|
end
|
107
|
-
elsif num_received == 1 && (note = docs[0]['jnote'] || docs[0]['wnote']) # assignment
|
108
|
-
code = docs[0]['code'] || Mongo::ErrorCode::BAD_VALUE # as of server version 2.5.5
|
109
|
-
raise OperationFailure.new(code.to_s + ': ' + note, code, docs[0])
|
110
112
|
end
|
111
113
|
|
112
114
|
docs[0]
|
@@ -120,8 +122,10 @@ module Mongo
|
|
120
122
|
# @param [Socket] socket a socket to use in lieu of checking out a new one.
|
121
123
|
# @param [Boolean] command (false) indicate whether this is a command. If this is a command,
|
122
124
|
# the message will be sent to the primary node.
|
123
|
-
# @param [
|
125
|
+
# @param [Symbol] read the read preference.
|
126
|
+
# @param [Boolean] exhaust (false) indicate whether the cursor should be exhausted. Set
|
124
127
|
# this to true only when the OP_QUERY_EXHAUST flag is set.
|
128
|
+
# @param [Boolean] compile_regex whether BSON regex objects should be compiled into Ruby regexes.
|
125
129
|
#
|
126
130
|
# @return [Array]
|
127
131
|
# An array whose indexes include [0] documents returned, [1] number of document received,
|
@@ -144,6 +144,20 @@ class ClientTest < Test::Unit::TestCase
|
|
144
144
|
assert_equal db.name, MongoClient::DEFAULT_DB_NAME
|
145
145
|
end
|
146
146
|
|
147
|
+
def test_from_uri_write_concern
|
148
|
+
con = MongoClient.from_uri("mongodb://#{host_port}")
|
149
|
+
db = con.db
|
150
|
+
coll = db.collection('from-uri-test')
|
151
|
+
assert_equal BSON::ObjectId, coll.insert({'a' => 1}).class
|
152
|
+
[con, db, coll].each do |component|
|
153
|
+
component.write_concern.each do |key,value|
|
154
|
+
assert_not_nil(value, "component #{component.class.inspect} should not have write concern #{key.inspect} field with nil value")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
assert_equal({:w => 1}, con.write_concern, "write concern should not have extra pairs that were not specified by the user")
|
158
|
+
assert_equal({:w => 1}, db.write_concern, "write concern should not have extra pairs that were not specified by the user")
|
159
|
+
assert_equal({:w => 1}, coll.write_concern, "write concern should not have extra pairs that were not specified by the user")
|
160
|
+
end
|
147
161
|
|
148
162
|
def test_server_version
|
149
163
|
assert_match(/\d\.\d+(\.\d+)?/, @client.server_version.to_s)
|
@@ -102,12 +102,10 @@ class CollectionTest < Test::Unit::TestCase
|
|
102
102
|
@@test.drop
|
103
103
|
@@test.insert([{ :a => 1 }, { :a => 1 }])
|
104
104
|
|
105
|
-
command =
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
:ordered => false
|
110
|
-
}
|
105
|
+
command = BSON::OrderedHash['delete', @@test.name,
|
106
|
+
:deletes, [{ :q => { :a => 1 }, :limit => 1 }],
|
107
|
+
:writeConcern, { :w => 1 },
|
108
|
+
:ordered, false]
|
111
109
|
|
112
110
|
result = @@db.command(command)
|
113
111
|
assert_equal 1, result['n']
|
@@ -119,12 +117,10 @@ class CollectionTest < Test::Unit::TestCase
|
|
119
117
|
@@test.drop
|
120
118
|
@@test.insert([{ :a => 1 }, { :a => 1 }])
|
121
119
|
|
122
|
-
command =
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
:ordered => true
|
127
|
-
}
|
120
|
+
command = BSON::OrderedHash['delete', @@test.name,
|
121
|
+
:deletes, [{ :q => { :a => 1 }, :limit => 0 }],
|
122
|
+
:writeConcern, { :w => 1 },
|
123
|
+
:ordered, true]
|
128
124
|
|
129
125
|
result = @@db.command(command)
|
130
126
|
assert_equal 2, result['n']
|
@@ -136,12 +132,10 @@ class CollectionTest < Test::Unit::TestCase
|
|
136
132
|
@@test.drop
|
137
133
|
@@test.insert([{ :a => 1 }, { :a => 1 }])
|
138
134
|
|
139
|
-
command =
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
:ordered => false
|
144
|
-
}
|
135
|
+
command = BSON::OrderedHash['delete', @@test.name,
|
136
|
+
:deletes, [{ :q => { :a => 1 }, :limit => 0 }],
|
137
|
+
:writeConcern, { :w => 1 },
|
138
|
+
:ordered, false]
|
145
139
|
|
146
140
|
result = @@db.command(command)
|
147
141
|
assert_equal 2, result['n']
|
@@ -153,11 +147,9 @@ class CollectionTest < Test::Unit::TestCase
|
|
153
147
|
@@test.drop
|
154
148
|
@@test.insert([{ :a => 1 }, { :a => 1 }])
|
155
149
|
|
156
|
-
command =
|
157
|
-
|
158
|
-
|
159
|
-
:ordered => false
|
160
|
-
}
|
150
|
+
command = BSON::OrderedHash['delete', @@test.name,
|
151
|
+
:deletes, [{ :q => { :a => 1 }, :limit => 0 }],
|
152
|
+
:ordered, false]
|
161
153
|
|
162
154
|
result = @@db.command(command)
|
163
155
|
assert_equal 2, result['n']
|
@@ -169,12 +161,10 @@ class CollectionTest < Test::Unit::TestCase
|
|
169
161
|
@@test.drop
|
170
162
|
@@test.insert([{ :a => 1 }, { :a => 1 }])
|
171
163
|
|
172
|
-
command =
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
:ordered => false
|
177
|
-
}
|
164
|
+
command = BSON::OrderedHash['delete', @@test.name,
|
165
|
+
:deletes, [{ :q => { '$set' => { :a => 1 }}, :limit => 0 }],
|
166
|
+
:writeConcern, { :w => 1 },
|
167
|
+
:ordered, false]
|
178
168
|
|
179
169
|
assert_raise Mongo::OperationFailure do
|
180
170
|
@@db.command(command)
|
@@ -184,12 +174,10 @@ class CollectionTest < Test::Unit::TestCase
|
|
184
174
|
def test_single_insert_write_command
|
185
175
|
@@test.drop
|
186
176
|
|
187
|
-
command =
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
:ordered => false
|
192
|
-
}
|
177
|
+
command = BSON::OrderedHash['insert', @@test.name,
|
178
|
+
:documents, [{ :a => 1 }],
|
179
|
+
:writeConcern, { :w => 1 },
|
180
|
+
:ordered, false]
|
193
181
|
|
194
182
|
result = @@db.command(command)
|
195
183
|
assert_equal 1, result['ok']
|
@@ -199,12 +187,10 @@ class CollectionTest < Test::Unit::TestCase
|
|
199
187
|
def test_multi_ordered_insert_write_command
|
200
188
|
@@test.drop
|
201
189
|
|
202
|
-
command =
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
:ordered => true
|
207
|
-
}
|
190
|
+
command = BSON::OrderedHash['insert', @@test.name,
|
191
|
+
:documents, [{ :a => 1 }, { :a => 2 }],
|
192
|
+
:writeConcern, { :w => 1 },
|
193
|
+
:ordered, true]
|
208
194
|
|
209
195
|
result = @@db.command(command)
|
210
196
|
assert_equal 1, result['ok']
|
@@ -214,12 +200,10 @@ class CollectionTest < Test::Unit::TestCase
|
|
214
200
|
def test_multi_unordered_insert_write_command
|
215
201
|
@@test.drop
|
216
202
|
|
217
|
-
command =
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
:ordered => false
|
222
|
-
}
|
203
|
+
command = BSON::OrderedHash['insert', @@test.name,
|
204
|
+
:documents, [{ :a => 1 }, { :a => 2 }],
|
205
|
+
:writeConcern, { :w => 1 },
|
206
|
+
:ordered, false]
|
223
207
|
|
224
208
|
result = @@db.command(command)
|
225
209
|
assert_equal 1, result['ok']
|
@@ -229,11 +213,9 @@ class CollectionTest < Test::Unit::TestCase
|
|
229
213
|
def test_insert_write_command_with_no_concern
|
230
214
|
@@test.drop
|
231
215
|
|
232
|
-
command =
|
233
|
-
|
234
|
-
|
235
|
-
:ordered => false
|
236
|
-
}
|
216
|
+
command = BSON::OrderedHash['insert', @@test.name,
|
217
|
+
:documents, [{ :a => 1 }, { :a => 2 }],
|
218
|
+
:ordered, false]
|
237
219
|
|
238
220
|
result = @@db.command(command)
|
239
221
|
assert_equal 1, result['ok']
|
@@ -242,14 +224,12 @@ class CollectionTest < Test::Unit::TestCase
|
|
242
224
|
|
243
225
|
def test_insert_write_command_with_error
|
244
226
|
@@test.drop
|
245
|
-
@@test.ensure_index(
|
227
|
+
@@test.ensure_index([[:a, 1]], { :unique => true })
|
246
228
|
|
247
|
-
command =
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
:ordered => false
|
252
|
-
}
|
229
|
+
command = BSON::OrderedHash['insert', @@test.name,
|
230
|
+
:documents, [{ :a => 1 }, { :a => 1 }],
|
231
|
+
:writeConcern, { :w => 1 },
|
232
|
+
:ordered, false]
|
253
233
|
|
254
234
|
assert_raise Mongo::OperationFailure do
|
255
235
|
@@db.command(command)
|
@@ -260,11 +240,9 @@ class CollectionTest < Test::Unit::TestCase
|
|
260
240
|
@@test.drop
|
261
241
|
@@test.insert([{ :a => 1 }, { :a => 2 }])
|
262
242
|
|
263
|
-
command =
|
264
|
-
|
265
|
-
|
266
|
-
:writeConcern => { :w => 1 }
|
267
|
-
}
|
243
|
+
command = BSON::OrderedHash['update', @@test.name,
|
244
|
+
:updates, [{ :q => { :a => 1 }, :u => { '$set' => { :a => 2 }}}],
|
245
|
+
:writeConcern, { :w => 1 }]
|
268
246
|
|
269
247
|
result = @@db.command(command)
|
270
248
|
assert_equal 1, result['ok']
|
@@ -276,15 +254,13 @@ class CollectionTest < Test::Unit::TestCase
|
|
276
254
|
@@test.drop
|
277
255
|
@@test.insert([{ :a => 1 }, { :a => 3 }])
|
278
256
|
|
279
|
-
command =
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
:ordered => true
|
287
|
-
}
|
257
|
+
command = BSON::OrderedHash['update', @@test.name,
|
258
|
+
:updates, [
|
259
|
+
{ :q => { :a => 1 }, :u => { '$set' => { :a => 2 }}},
|
260
|
+
{ :q => { :a => 3 }, :u => { '$set' => { :a => 4 }}}
|
261
|
+
],
|
262
|
+
:writeConcern, { :w => 1 },
|
263
|
+
:ordered, true]
|
288
264
|
|
289
265
|
result = @@db.command(command)
|
290
266
|
assert_equal 1, result['ok']
|
@@ -297,15 +273,13 @@ class CollectionTest < Test::Unit::TestCase
|
|
297
273
|
@@test.drop
|
298
274
|
@@test.insert([{ :a => 1 }, { :a => 3 }])
|
299
275
|
|
300
|
-
command =
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
:ordered => false
|
308
|
-
}
|
276
|
+
command = BSON::OrderedHash['update', @@test.name,
|
277
|
+
:updates, [
|
278
|
+
{ :q => { :a => 1 }, :u => { '$set' => { :a => 2 }}},
|
279
|
+
{ :q => { :a => 3 }, :u => { '$set' => { :a => 4 }}}
|
280
|
+
],
|
281
|
+
:writeConcern, { :w => 1 },
|
282
|
+
:ordered, false]
|
309
283
|
|
310
284
|
result = @@db.command(command)
|
311
285
|
assert_equal 1, result['ok']
|
@@ -318,14 +292,12 @@ class CollectionTest < Test::Unit::TestCase
|
|
318
292
|
@@test.drop
|
319
293
|
@@test.insert([{ :a => 1 }, { :a => 3 }])
|
320
294
|
|
321
|
-
command =
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
:ordered => false
|
328
|
-
}
|
295
|
+
command = BSON::OrderedHash['update', @@test.name,
|
296
|
+
:updates, [
|
297
|
+
{ :q => { :a => 1 }, :u => { '$set' => { :a => 2 }}},
|
298
|
+
{ :q => { :a => 3 }, :u => { '$set' => { :a => 4 }}}
|
299
|
+
],
|
300
|
+
:ordered, false]
|
329
301
|
|
330
302
|
result = @@db.command(command)
|
331
303
|
assert_equal 1, result['ok']
|
@@ -336,16 +308,14 @@ class CollectionTest < Test::Unit::TestCase
|
|
336
308
|
|
337
309
|
def test_update_write_command_with_error
|
338
310
|
@@test.drop
|
339
|
-
@@test.ensure_index(
|
311
|
+
@@test.ensure_index([[:a, 1]], { :unique => true })
|
340
312
|
@@test.insert([{ :a => 1 }, { :a => 2 }])
|
341
313
|
|
342
|
-
command =
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
:ordered => false
|
348
|
-
}
|
314
|
+
command = BSON::OrderedHash['update', @@test.name,
|
315
|
+
:updates, [
|
316
|
+
{ :q => { :a => 2 }, :u => { '$set' => { :a => 1 }}}
|
317
|
+
],
|
318
|
+
:ordered, false]
|
349
319
|
|
350
320
|
assert_raise Mongo::OperationFailure do
|
351
321
|
@@db.command(command)
|
@@ -877,7 +847,7 @@ class CollectionTest < Test::Unit::TestCase
|
|
877
847
|
if @@version < "2.5.3"
|
878
848
|
def test_jnote_raises_exception
|
879
849
|
with_no_journaling(@@client) do
|
880
|
-
ex = assert_raise Mongo::
|
850
|
+
ex = assert_raise Mongo::WriteConcernError do
|
881
851
|
@@test.insert({:foo => 1}, :j => true)
|
882
852
|
end
|
883
853
|
result = ex.result
|
@@ -886,7 +856,7 @@ class CollectionTest < Test::Unit::TestCase
|
|
886
856
|
end
|
887
857
|
|
888
858
|
def test_wnote_raises_exception
|
889
|
-
ex = assert_raise Mongo::
|
859
|
+
ex = assert_raise Mongo::WriteConcernError do
|
890
860
|
@@test.insert({:foo => 1}, :w => 2)
|
891
861
|
end
|
892
862
|
result = ex.result
|