mongo 2.4.3 → 2.5.0.beta
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 +3 -2
- data.tar.gz.sig +0 -0
- data/lib/mongo.rb +3 -2
- data/lib/mongo/auth/cr.rb +6 -4
- data/lib/mongo/auth/cr/conversation.rb +33 -17
- data/lib/mongo/auth/ldap.rb +4 -2
- data/lib/mongo/auth/ldap/conversation.rb +19 -9
- data/lib/mongo/auth/scram.rb +7 -4
- data/lib/mongo/auth/scram/conversation.rb +62 -24
- data/lib/mongo/auth/user.rb +10 -0
- data/lib/mongo/auth/user/view.rb +44 -22
- data/lib/mongo/auth/x509.rb +4 -2
- data/lib/mongo/auth/x509/conversation.rb +19 -9
- data/lib/mongo/bulk_write.rb +33 -27
- data/lib/mongo/bulk_write/combineable.rb +5 -0
- data/lib/mongo/bulk_write/transformable.rb +2 -0
- data/lib/mongo/bulk_write/validatable.rb +4 -0
- data/lib/mongo/client.rb +123 -12
- data/lib/mongo/cluster.rb +52 -11
- data/lib/mongo/cluster/app_metadata.rb +8 -2
- data/lib/mongo/cluster/cursor_reaper.rb +0 -1
- data/lib/mongo/cluster/topology.rb +1 -1
- data/lib/mongo/collection.rb +114 -27
- data/lib/mongo/collection/view.rb +8 -2
- data/lib/mongo/collection/view/aggregation.rb +11 -7
- data/lib/mongo/collection/view/builder/aggregation.rb +5 -1
- data/lib/mongo/collection/view/builder/find_command.rb +5 -3
- data/lib/mongo/collection/view/builder/map_reduce.rb +11 -3
- data/lib/mongo/collection/view/builder/op_query.rb +1 -1
- data/lib/mongo/collection/view/change_stream.rb +160 -0
- data/lib/mongo/collection/view/change_stream/retryable.rb +57 -0
- data/lib/mongo/collection/view/iterable.rb +11 -10
- data/lib/mongo/collection/view/map_reduce.rb +22 -18
- data/lib/mongo/collection/view/readable.rb +51 -37
- data/lib/mongo/collection/view/writable.rb +72 -40
- data/lib/mongo/cursor.rb +25 -4
- data/lib/mongo/cursor/builder/get_more_command.rb +4 -2
- data/lib/mongo/database.rb +22 -11
- data/lib/mongo/database/view.rb +16 -12
- data/lib/mongo/error.rb +5 -0
- data/lib/mongo/error/invalid_session.rb +36 -0
- data/lib/mongo/error/missing_resume_token.rb +39 -0
- data/lib/mongo/error/operation_failure.rb +17 -0
- data/lib/mongo/error/parser.rb +3 -2
- data/lib/mongo/error/unknown_payload_type.rb +41 -0
- data/lib/mongo/error/unsupported_array_filters.rb +51 -0
- data/lib/mongo/error/unsupported_message_type.rb +23 -0
- data/lib/mongo/grid/fs_bucket.rb +5 -4
- data/lib/mongo/grid/stream/read.rb +3 -2
- data/lib/mongo/grid/stream/write.rb +2 -2
- data/lib/mongo/index/view.rb +35 -25
- data/lib/mongo/monitoring/event/secure.rb +14 -0
- data/lib/mongo/operation.rb +16 -0
- data/lib/mongo/operation/commands.rb +1 -0
- data/lib/mongo/operation/commands/aggregate.rb +9 -5
- data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
- data/lib/mongo/operation/commands/collections_info.rb +6 -6
- data/lib/mongo/operation/commands/command.rb +2 -1
- data/lib/mongo/operation/commands/create.rb +6 -2
- data/lib/mongo/operation/commands/drop.rb +6 -2
- data/lib/mongo/operation/commands/drop_database.rb +6 -2
- data/lib/mongo/operation/commands/explain.rb +27 -0
- data/lib/mongo/operation/commands/explain/result.rb +52 -0
- data/lib/mongo/operation/commands/indexes.rb +1 -1
- data/lib/mongo/operation/commands/list_collections.rb +1 -1
- data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce.rb +8 -4
- data/lib/mongo/operation/commands/map_reduce/result.rb +13 -1
- data/lib/mongo/operation/commands/user_query.rb +1 -1
- data/lib/mongo/operation/commands/users_info.rb +6 -2
- data/lib/mongo/operation/executable.rb +4 -1
- data/lib/mongo/operation/read_preference.rb +10 -5
- data/lib/mongo/operation/result.rb +26 -2
- data/lib/mongo/operation/specifiable.rb +13 -1
- data/lib/mongo/operation/uses_command_op_msg.rb +47 -0
- data/lib/mongo/operation/write/bulk/bulkable.rb +4 -1
- data/lib/mongo/operation/write/bulk/insert/result.rb +4 -4
- data/lib/mongo/operation/write/command/create_index.rb +6 -1
- data/lib/mongo/operation/write/command/delete.rb +28 -4
- data/lib/mongo/operation/write/command/drop_index.rb +6 -1
- data/lib/mongo/operation/write/command/insert.rb +22 -18
- data/lib/mongo/operation/write/command/update.rb +24 -9
- data/lib/mongo/operation/write/command/writable.rb +14 -1
- data/lib/mongo/operation/write/insert.rb +4 -1
- data/lib/mongo/operation/write/insert/result.rb +2 -2
- data/lib/mongo/operation/write/update.rb +7 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +20 -3
- data/lib/mongo/protocol.rb +3 -0
- data/lib/mongo/protocol/bit_vector.rb +2 -2
- data/lib/mongo/protocol/compressed.rb +135 -0
- data/lib/mongo/protocol/delete.rb +8 -6
- data/lib/mongo/protocol/get_more.rb +8 -6
- data/lib/mongo/protocol/insert.rb +8 -6
- data/lib/mongo/protocol/kill_cursors.rb +8 -6
- data/lib/mongo/protocol/message.rb +31 -3
- data/lib/mongo/protocol/msg.rb +172 -0
- data/lib/mongo/protocol/query.rb +26 -6
- data/lib/mongo/protocol/registry.rb +76 -0
- data/lib/mongo/protocol/reply.rb +10 -5
- data/lib/mongo/protocol/serializers.rb +224 -0
- data/lib/mongo/protocol/update.rb +8 -6
- data/lib/mongo/retryable.rb +4 -2
- data/lib/mongo/server.rb +6 -3
- data/lib/mongo/server/connectable.rb +1 -1
- data/lib/mongo/server/connection.rb +30 -8
- data/lib/mongo/server/description.rb +25 -1
- data/lib/mongo/server/description/features.rb +4 -1
- data/lib/mongo/server/monitor.rb +5 -0
- data/lib/mongo/server/monitor/connection.rb +50 -2
- data/lib/mongo/server_selector/nearest.rb +10 -4
- data/lib/mongo/server_selector/primary.rb +20 -0
- data/lib/mongo/server_selector/primary_preferred.rb +10 -4
- data/lib/mongo/server_selector/secondary.rb +10 -4
- data/lib/mongo/server_selector/secondary_preferred.rb +24 -4
- data/lib/mongo/session.rb +180 -0
- data/lib/mongo/session/server_session.rb +73 -0
- data/lib/mongo/session/session_pool.rb +161 -0
- data/lib/mongo/uri.rb +11 -0
- data/lib/mongo/version.rb +1 -1
- data/mongo.gemspec +2 -1
- data/spec/mongo/auth/cr_spec.rb +12 -0
- data/spec/mongo/auth/ldap_spec.rb +2 -0
- data/spec/mongo/auth/scram/conversation_spec.rb +6 -6
- data/spec/mongo/auth/scram_spec.rb +25 -1
- data/spec/mongo/auth/user/view_spec.rb +268 -76
- data/spec/mongo/auth/x509_spec.rb +2 -0
- data/spec/mongo/bulk_write_spec.rb +435 -5
- data/spec/mongo/client_spec.rb +356 -39
- data/spec/mongo/cluster/app_metadata_spec.rb +2 -2
- data/spec/mongo/cluster_spec.rb +176 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +33 -12
- data/spec/mongo/collection/view/builder/find_command_spec.rb +46 -6
- data/spec/mongo/collection/view/change_stream_spec.rb +814 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +94 -17
- data/spec/mongo/collection/view/readable_spec.rb +3 -12
- data/spec/mongo/collection_spec.rb +1048 -42
- data/spec/mongo/cursor/builder/get_more_command_spec.rb +19 -0
- data/spec/mongo/cursor_spec.rb +2 -2
- data/spec/mongo/database_spec.rb +50 -1
- data/spec/mongo/grid/fs_bucket_spec.rb +225 -137
- data/spec/mongo/grid/stream/read_spec.rb +2 -2
- data/spec/mongo/index/view_spec.rb +146 -8
- data/spec/mongo/monitoring/event/secure_spec.rb +42 -0
- data/spec/mongo/operation/read/query_spec.rb +2 -1
- data/spec/mongo/operation/specifiable_spec.rb +2 -2
- data/spec/mongo/operation/write/command/delete_spec.rb +96 -13
- data/spec/mongo/operation/write/command/insert_spec.rb +111 -12
- data/spec/mongo/operation/write/command/update_spec.rb +93 -10
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +1 -1
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/protocol/compressed_spec.rb +66 -0
- data/spec/mongo/protocol/delete_spec.rb +14 -0
- data/spec/mongo/protocol/get_more_spec.rb +14 -0
- data/spec/mongo/protocol/insert_spec.rb +14 -0
- data/spec/mongo/protocol/kill_cursors_spec.rb +14 -0
- data/spec/mongo/protocol/msg_spec.rb +499 -0
- data/spec/mongo/protocol/query_spec.rb +45 -0
- data/spec/mongo/protocol/registry_spec.rb +31 -0
- data/spec/mongo/protocol/reply_spec.rb +14 -0
- data/spec/mongo/protocol/update_spec.rb +14 -0
- data/spec/mongo/retryable_spec.rb +6 -2
- data/spec/mongo/sdam_spec.rb +4 -0
- data/spec/mongo/server/connection_spec.rb +4 -2
- data/spec/mongo/server/description_spec.rb +28 -1
- data/spec/mongo/session/server_session_spec.rb +16 -0
- data/spec/mongo/session/session_pool_spec.rb +194 -0
- data/spec/mongo/uri_spec.rb +31 -2
- data/spec/spec_helper.rb +104 -0
- data/spec/support/authorization.rb +6 -1
- data/spec/support/crud.rb +3 -1
- data/spec/support/crud/write.rb +6 -1
- data/spec/support/crud_tests/write/findOneAndUpdate-arrayFilters.yml +69 -0
- data/spec/support/crud_tests/write/updateMany-arrayFilters.yml +63 -0
- data/spec/support/crud_tests/write/updateOne-arrayFilters.yml +109 -0
- data/spec/support/sdam/rs/discover_arbiters.yml +1 -1
- data/spec/support/sdam/rs/discover_passives.yml +2 -2
- data/spec/support/sdam/rs/discover_primary.yml +1 -1
- data/spec/support/sdam/rs/discover_secondary.yml +1 -1
- data/spec/support/sdam/rs/discovery.yml +4 -4
- data/spec/support/sdam/rs/equal_electionids.yml +1 -0
- data/spec/support/sdam/rs/ghost_discovered.yml +1 -1
- data/spec/support/sdam/rs/hosts_differ_from_seeds.yml +1 -1
- data/spec/support/sdam/rs/ls_timeout.yml +88 -0
- data/spec/support/sdam/rs/member_reconfig.yml +2 -2
- data/spec/support/sdam/rs/member_standalone.yml +2 -2
- data/spec/support/sdam/rs/new_primary.yml +2 -2
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +3 -0
- data/spec/support/sdam/rs/new_primary_new_setversion.yml +3 -0
- data/spec/support/sdam/rs/new_primary_wrong_set_name.yml +2 -2
- data/spec/support/sdam/rs/non_rs_member.yml +1 -1
- data/spec/support/sdam/rs/normalize_case.yml +1 -1
- data/spec/support/sdam/rs/null_election_id.yml +4 -0
- data/spec/support/sdam/rs/primary_becomes_standalone.yml +2 -2
- data/spec/support/sdam/rs/primary_changes_set_name.yml +2 -2
- data/spec/support/sdam/rs/primary_disconnect.yml +2 -2
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +5 -0
- data/spec/support/sdam/rs/primary_disconnect_setversion.yml +5 -0
- data/spec/support/sdam/rs/primary_hint_from_secondary_with_mismatched_me.yml +58 -0
- data/spec/support/sdam/rs/primary_reports_new_member.yml +4 -4
- data/spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml +2 -2
- data/spec/support/sdam/rs/primary_wrong_set_name.yml +1 -1
- data/spec/support/sdam/rs/response_from_removed.yml +2 -2
- data/spec/support/sdam/rs/rsother_discovered.yml +1 -1
- data/spec/support/sdam/rs/sec_not_auth.yml +1 -1
- data/spec/support/sdam/rs/secondary_wrong_set_name.yml +1 -1
- data/spec/support/sdam/rs/secondary_wrong_set_name_with_primary.yml +2 -2
- data/spec/support/sdam/rs/setversion_without_electionid.yml +2 -0
- data/spec/support/sdam/rs/stepdown_change_set_name.yml +2 -2
- data/spec/support/sdam/rs/unexpected_mongos.yml +1 -1
- data/spec/support/sdam/rs/use_setversion_without_electionid.yml +3 -0
- data/spec/support/sdam/rs/wrong_set_name.yml +1 -1
- data/spec/support/sdam/sharded/ls_timeout_mongos.yml +97 -0
- data/spec/support/sdam/sharded/mongos_disconnect.yml +3 -3
- data/spec/support/sdam/sharded/multiple_mongoses.yml +1 -1
- data/spec/support/sdam/sharded/non_mongos_removed.yml +1 -1
- data/spec/support/sdam/sharded/normalize_uri_case.yml +1 -1
- data/spec/support/sdam/single/direct_connection_external_ip.yml +1 -1
- data/spec/support/sdam/single/direct_connection_mongos.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rsarbiter.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rsprimary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rssecondary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_slave.yml +1 -1
- data/spec/support/sdam/single/direct_connection_standalone.yml +1 -1
- data/spec/support/sdam/single/ls_timeout_standalone.yml +35 -0
- data/spec/support/sdam/single/not_ok_response.yml +1 -1
- data/spec/support/sdam/single/standalone_removed.yml +1 -1
- data/spec/support/sdam/single/unavailable_seed.yml +1 -1
- data/spec/support/server_discovery_and_monitoring.rb +4 -0
- data/spec/support/shared/session.rb +236 -0
- metadata +53 -15
- metadata.gz.sig +0 -0
@@ -18,6 +18,8 @@ describe Mongo::Auth::X509 do
|
|
18
18
|
double('cluster').tap do |cl|
|
19
19
|
allow(cl).to receive(:topology).and_return(topology)
|
20
20
|
allow(cl).to receive(:app_metadata).and_return(app_metadata)
|
21
|
+
allow(cl).to receive(:cluster_time).and_return(nil)
|
22
|
+
allow(cl).to receive(:update_cluster_time)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -27,8 +27,11 @@ describe Mongo::BulkWrite do
|
|
27
27
|
{ locale: 'en_US', strength: 2 }
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
let(:array_filters) do
|
31
|
+
[{ 'i.y' => 3}]
|
32
|
+
end
|
31
33
|
|
34
|
+
describe '#execute' do
|
32
35
|
shared_examples_for 'an executable bulk write' do
|
33
36
|
|
34
37
|
context 'when providing a bad operation' do
|
@@ -74,6 +77,23 @@ describe Mongo::BulkWrite do
|
|
74
77
|
it 'sets the document index on the error' do
|
75
78
|
expect(error.result[Mongo::Error::WRITE_ERRORS].first['index']).to eq(2)
|
76
79
|
end
|
80
|
+
|
81
|
+
context 'when a session is provided' do
|
82
|
+
|
83
|
+
let(:extra_options) do
|
84
|
+
{ session: session }
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:client) do
|
88
|
+
authorized_client
|
89
|
+
end
|
90
|
+
|
91
|
+
let(:failed_operation) do
|
92
|
+
bulk_write.execute
|
93
|
+
end
|
94
|
+
|
95
|
+
it_behaves_like 'a failed operation using a session'
|
96
|
+
end
|
77
97
|
end
|
78
98
|
|
79
99
|
context 'when provided a single insert one' do
|
@@ -96,6 +116,23 @@ describe Mongo::BulkWrite do
|
|
96
116
|
expect(authorized_collection.find.first['_id']).to eq(0)
|
97
117
|
end
|
98
118
|
|
119
|
+
context 'when a session is provided' do
|
120
|
+
|
121
|
+
let(:operation) do
|
122
|
+
result
|
123
|
+
end
|
124
|
+
|
125
|
+
let(:extra_options) do
|
126
|
+
{ session: session }
|
127
|
+
end
|
128
|
+
|
129
|
+
let(:client) do
|
130
|
+
authorized_client
|
131
|
+
end
|
132
|
+
|
133
|
+
it_behaves_like 'an operation using a session'
|
134
|
+
end
|
135
|
+
|
99
136
|
context 'when there is a write concern error' do
|
100
137
|
|
101
138
|
context 'when the server version is < 2.6' do
|
@@ -114,6 +151,23 @@ describe Mongo::BulkWrite do
|
|
114
151
|
bulk_write_invalid_write_concern.execute
|
115
152
|
}.to raise_error(Mongo::Error::OperationFailure)
|
116
153
|
end
|
154
|
+
|
155
|
+
context 'when a session is provided' do
|
156
|
+
|
157
|
+
let(:extra_options) do
|
158
|
+
{ session: session }
|
159
|
+
end
|
160
|
+
|
161
|
+
let(:client) do
|
162
|
+
collection_invalid_write_concern.client
|
163
|
+
end
|
164
|
+
|
165
|
+
let(:failed_operation) do
|
166
|
+
bulk_write_invalid_write_concern.execute
|
167
|
+
end
|
168
|
+
|
169
|
+
it_behaves_like 'a failed operation using a session'
|
170
|
+
end
|
117
171
|
end
|
118
172
|
end
|
119
173
|
end
|
@@ -168,6 +222,23 @@ describe Mongo::BulkWrite do
|
|
168
222
|
bulk_write_invalid_write_concern.execute
|
169
223
|
}.to raise_error(Mongo::Error::OperationFailure)
|
170
224
|
end
|
225
|
+
|
226
|
+
context 'when a session is provided' do
|
227
|
+
|
228
|
+
let(:extra_options) do
|
229
|
+
{ session: session }
|
230
|
+
end
|
231
|
+
|
232
|
+
let(:client) do
|
233
|
+
collection_invalid_write_concern.client
|
234
|
+
end
|
235
|
+
|
236
|
+
let(:failed_operation) do
|
237
|
+
bulk_write_invalid_write_concern.execute
|
238
|
+
end
|
239
|
+
|
240
|
+
it_behaves_like 'a failed operation using a session'
|
241
|
+
end
|
171
242
|
end
|
172
243
|
end
|
173
244
|
end
|
@@ -191,6 +262,23 @@ describe Mongo::BulkWrite do
|
|
191
262
|
expect(authorized_collection.find(_id: 0).count).to eq(0)
|
192
263
|
end
|
193
264
|
|
265
|
+
context 'when a session is provided' do
|
266
|
+
|
267
|
+
let(:operation) do
|
268
|
+
result
|
269
|
+
end
|
270
|
+
|
271
|
+
let(:client) do
|
272
|
+
authorized_client
|
273
|
+
end
|
274
|
+
|
275
|
+
let(:extra_options) do
|
276
|
+
{ session: session }
|
277
|
+
end
|
278
|
+
|
279
|
+
it_behaves_like 'an operation using a session'
|
280
|
+
end
|
281
|
+
|
194
282
|
context 'when there is a write concern error' do
|
195
283
|
|
196
284
|
context 'when the server version is < 2.6' do
|
@@ -209,6 +297,23 @@ describe Mongo::BulkWrite do
|
|
209
297
|
bulk_write_invalid_write_concern.execute
|
210
298
|
}.to raise_error(Mongo::Error::OperationFailure)
|
211
299
|
end
|
300
|
+
|
301
|
+
context 'when a session is provided' do
|
302
|
+
|
303
|
+
let(:extra_options) do
|
304
|
+
{ session: session }
|
305
|
+
end
|
306
|
+
|
307
|
+
let(:client) do
|
308
|
+
collection_invalid_write_concern.client
|
309
|
+
end
|
310
|
+
|
311
|
+
let(:failed_operation) do
|
312
|
+
bulk_write_invalid_write_concern.execute
|
313
|
+
end
|
314
|
+
|
315
|
+
it_behaves_like 'a failed operation using a session'
|
316
|
+
end
|
212
317
|
end
|
213
318
|
|
214
319
|
context 'when the write has a collation specified' do
|
@@ -283,6 +388,111 @@ describe Mongo::BulkWrite do
|
|
283
388
|
end
|
284
389
|
end
|
285
390
|
|
391
|
+
context 'when bulk executing update_one' do
|
392
|
+
|
393
|
+
context 'when the write has specified arrayFilters' do
|
394
|
+
|
395
|
+
before do
|
396
|
+
authorized_collection.insert_one(_id: 1, x: [{ y: 1 }, { y: 2 }, { y: 3 }])
|
397
|
+
end
|
398
|
+
|
399
|
+
let(:requests) do
|
400
|
+
[{
|
401
|
+
update_one: {
|
402
|
+
filter: { _id: 1 },
|
403
|
+
update: { '$set' => { 'x.$[i].y' => 5 } },
|
404
|
+
array_filters: array_filters,
|
405
|
+
}
|
406
|
+
}]
|
407
|
+
end
|
408
|
+
|
409
|
+
context 'when the server selected supports arrayFilters', if: array_filters_enabled? do
|
410
|
+
|
411
|
+
let!(:result) do
|
412
|
+
bulk_write.execute
|
413
|
+
end
|
414
|
+
|
415
|
+
it 'applies the arrayFilters' do
|
416
|
+
expect(result.matched_count).to eq(1)
|
417
|
+
expect(result.modified_count).to eq(1)
|
418
|
+
expect(authorized_collection.find(_id: 1).first['x'].last['y']).to eq(5)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
context 'when the server selected does not support arrayFilters', unless: array_filters_enabled? do
|
423
|
+
|
424
|
+
it 'raises an exception' do
|
425
|
+
expect {
|
426
|
+
bulk_write.execute
|
427
|
+
}.to raise_exception(Mongo::Error::UnsupportedArrayFilters)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
context 'when bulk executing update_many' do
|
434
|
+
|
435
|
+
context 'when the write has specified arrayFilters' do
|
436
|
+
|
437
|
+
before do
|
438
|
+
authorized_collection.insert_many([{
|
439
|
+
_id: 1, x: [
|
440
|
+
{ y: 1 },
|
441
|
+
{ y: 2 },
|
442
|
+
{ y: 3 }
|
443
|
+
]
|
444
|
+
},
|
445
|
+
{
|
446
|
+
_id: 2,
|
447
|
+
x: [
|
448
|
+
{ y: 3 },
|
449
|
+
{ y: 2 },
|
450
|
+
{ y: 1 }
|
451
|
+
]
|
452
|
+
}])
|
453
|
+
end
|
454
|
+
|
455
|
+
let(:selector) do
|
456
|
+
{ '$or' => [{ _id: 1 }, { _id: 2 }]}
|
457
|
+
end
|
458
|
+
|
459
|
+
let(:requests) do
|
460
|
+
[{
|
461
|
+
update_many: {
|
462
|
+
filter: { '$or' => [{ _id: 1 }, { _id: 2 }]},
|
463
|
+
update: { '$set' => { 'x.$[i].y' => 5 } },
|
464
|
+
array_filters: array_filters,
|
465
|
+
}
|
466
|
+
}]
|
467
|
+
end
|
468
|
+
|
469
|
+
context 'when the server selected supports arrayFilters', if: array_filters_enabled? do
|
470
|
+
|
471
|
+
let!(:result) do
|
472
|
+
bulk_write.execute
|
473
|
+
end
|
474
|
+
|
475
|
+
it 'applies the arrayFilters' do
|
476
|
+
expect(result.matched_count).to eq(2)
|
477
|
+
expect(result.modified_count).to eq(2)
|
478
|
+
|
479
|
+
docs = authorized_collection.find(selector, sort: { _id: 1 }).to_a
|
480
|
+
expect(docs[0]['x']).to eq ([{ 'y' => 1 }, { 'y' => 2 }, { 'y' => 5}])
|
481
|
+
expect(docs[1]['x']).to eq ([{ 'y' => 5 }, { 'y' => 2 }, { 'y' => 1}])
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
context 'when the server selected does not support arrayFilters', unless: array_filters_enabled? do
|
486
|
+
|
487
|
+
it 'raises an exception' do
|
488
|
+
expect {
|
489
|
+
bulk_write.execute
|
490
|
+
}.to raise_exception(Mongo::Error::UnsupportedArrayFilters)
|
491
|
+
end
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
286
496
|
context 'when multiple documents match delete selector' do
|
287
497
|
|
288
498
|
before do
|
@@ -329,6 +539,23 @@ describe Mongo::BulkWrite do
|
|
329
539
|
expect(authorized_collection.find(_id: { '$in'=> [ 0, 1, 2 ]}).count).to eq(0)
|
330
540
|
end
|
331
541
|
|
542
|
+
context 'when a session is provided' do
|
543
|
+
|
544
|
+
let(:operation) do
|
545
|
+
result
|
546
|
+
end
|
547
|
+
|
548
|
+
let(:client) do
|
549
|
+
authorized_client
|
550
|
+
end
|
551
|
+
|
552
|
+
let(:extra_options) do
|
553
|
+
{ session: session }
|
554
|
+
end
|
555
|
+
|
556
|
+
it_behaves_like 'an operation using a session'
|
557
|
+
end
|
558
|
+
|
332
559
|
context 'when there is a write concern error' do
|
333
560
|
|
334
561
|
context 'when the server version is < 2.6' do
|
@@ -347,6 +574,23 @@ describe Mongo::BulkWrite do
|
|
347
574
|
bulk_write_invalid_write_concern.execute
|
348
575
|
}.to raise_error(Mongo::Error::OperationFailure)
|
349
576
|
end
|
577
|
+
|
578
|
+
context 'when a session is provided' do
|
579
|
+
|
580
|
+
let(:extra_options) do
|
581
|
+
{ session: session }
|
582
|
+
end
|
583
|
+
|
584
|
+
let(:client) do
|
585
|
+
collection_invalid_write_concern.client
|
586
|
+
end
|
587
|
+
|
588
|
+
let(:failed_operation) do
|
589
|
+
bulk_write_invalid_write_concern.execute
|
590
|
+
end
|
591
|
+
|
592
|
+
it_behaves_like 'a failed operation using a session'
|
593
|
+
end
|
350
594
|
end
|
351
595
|
end
|
352
596
|
|
@@ -446,6 +690,23 @@ describe Mongo::BulkWrite do
|
|
446
690
|
expect(authorized_collection.find(_id: 0).count).to eq(0)
|
447
691
|
end
|
448
692
|
|
693
|
+
context 'when a session is provided' do
|
694
|
+
|
695
|
+
let(:operation) do
|
696
|
+
result
|
697
|
+
end
|
698
|
+
|
699
|
+
let(:client) do
|
700
|
+
authorized_client
|
701
|
+
end
|
702
|
+
|
703
|
+
let(:extra_options) do
|
704
|
+
{ session: session }
|
705
|
+
end
|
706
|
+
|
707
|
+
it_behaves_like 'an operation using a session'
|
708
|
+
end
|
709
|
+
|
449
710
|
context 'when there is a write concern error' do
|
450
711
|
|
451
712
|
context 'when the server version is < 2.6' do
|
@@ -464,6 +725,23 @@ describe Mongo::BulkWrite do
|
|
464
725
|
bulk_write_invalid_write_concern.execute
|
465
726
|
}.to raise_error(Mongo::Error::OperationFailure)
|
466
727
|
end
|
728
|
+
|
729
|
+
context 'when a session is provided' do
|
730
|
+
|
731
|
+
let(:extra_options) do
|
732
|
+
{ session: session }
|
733
|
+
end
|
734
|
+
|
735
|
+
let(:client) do
|
736
|
+
collection_invalid_write_concern.client
|
737
|
+
end
|
738
|
+
|
739
|
+
let(:failed_operation) do
|
740
|
+
bulk_write_invalid_write_concern.execute
|
741
|
+
end
|
742
|
+
|
743
|
+
it_behaves_like 'a failed operation using a session'
|
744
|
+
end
|
467
745
|
end
|
468
746
|
end
|
469
747
|
|
@@ -566,6 +844,23 @@ describe Mongo::BulkWrite do
|
|
566
844
|
expect(authorized_collection.find(_id: { '$in'=> [ 0, 1, 2 ]}).count).to eq(0)
|
567
845
|
end
|
568
846
|
|
847
|
+
context 'when a session is provided' do
|
848
|
+
|
849
|
+
let(:operation) do
|
850
|
+
result
|
851
|
+
end
|
852
|
+
|
853
|
+
let(:client) do
|
854
|
+
authorized_client
|
855
|
+
end
|
856
|
+
|
857
|
+
let(:extra_options) do
|
858
|
+
{ session: session }
|
859
|
+
end
|
860
|
+
|
861
|
+
it_behaves_like 'an operation using a session'
|
862
|
+
end
|
863
|
+
|
569
864
|
context 'when there is a write concern error' do
|
570
865
|
|
571
866
|
context 'when the server version is < 2.6' do
|
@@ -584,6 +879,23 @@ describe Mongo::BulkWrite do
|
|
584
879
|
bulk_write_invalid_write_concern.execute
|
585
880
|
}.to raise_error(Mongo::Error::OperationFailure)
|
586
881
|
end
|
882
|
+
|
883
|
+
context 'when a session is provided' do
|
884
|
+
|
885
|
+
let(:operation) do
|
886
|
+
result
|
887
|
+
end
|
888
|
+
|
889
|
+
let(:client) do
|
890
|
+
authorized_client
|
891
|
+
end
|
892
|
+
|
893
|
+
let(:extra_options) do
|
894
|
+
{ session: session }
|
895
|
+
end
|
896
|
+
|
897
|
+
it_behaves_like 'an operation using a session'
|
898
|
+
end
|
587
899
|
end
|
588
900
|
end
|
589
901
|
|
@@ -690,6 +1002,23 @@ describe Mongo::BulkWrite do
|
|
690
1002
|
expect(authorized_collection.find(_id: 0).first[:name]).to eq('test')
|
691
1003
|
end
|
692
1004
|
|
1005
|
+
context 'when a session is provided' do
|
1006
|
+
|
1007
|
+
let(:operation) do
|
1008
|
+
result
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
let(:client) do
|
1012
|
+
authorized_client
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
let(:extra_options) do
|
1016
|
+
{ session: session }
|
1017
|
+
end
|
1018
|
+
|
1019
|
+
it_behaves_like 'an operation using a session'
|
1020
|
+
end
|
1021
|
+
|
693
1022
|
context 'when there is a write concern error' do
|
694
1023
|
|
695
1024
|
context 'when the server version is < 2.6' do
|
@@ -708,6 +1037,23 @@ describe Mongo::BulkWrite do
|
|
708
1037
|
bulk_write_invalid_write_concern.execute
|
709
1038
|
}.to raise_error(Mongo::Error::OperationFailure)
|
710
1039
|
end
|
1040
|
+
|
1041
|
+
context 'when a session is provided' do
|
1042
|
+
|
1043
|
+
let(:extra_options) do
|
1044
|
+
{ session: session }
|
1045
|
+
end
|
1046
|
+
|
1047
|
+
let(:client) do
|
1048
|
+
collection_invalid_write_concern.client
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
let(:failed_operation) do
|
1052
|
+
bulk_write_invalid_write_concern.execute
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
it_behaves_like 'a failed operation using a session'
|
1056
|
+
end
|
711
1057
|
end
|
712
1058
|
end
|
713
1059
|
|
@@ -860,6 +1206,23 @@ describe Mongo::BulkWrite do
|
|
860
1206
|
expect(result.matched_count).to eq(1)
|
861
1207
|
end
|
862
1208
|
|
1209
|
+
context 'when a session is provided' do
|
1210
|
+
|
1211
|
+
let(:operation) do
|
1212
|
+
result
|
1213
|
+
end
|
1214
|
+
|
1215
|
+
let(:client) do
|
1216
|
+
authorized_client
|
1217
|
+
end
|
1218
|
+
|
1219
|
+
let(:extra_options) do
|
1220
|
+
{ session: session }
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
it_behaves_like 'an operation using a session'
|
1224
|
+
end
|
1225
|
+
|
863
1226
|
context 'when documents match but are not modified' do
|
864
1227
|
|
865
1228
|
before do
|
@@ -923,6 +1286,23 @@ describe Mongo::BulkWrite do
|
|
923
1286
|
bulk_write_invalid_write_concern.execute
|
924
1287
|
}.to raise_error(Mongo::Error::OperationFailure)
|
925
1288
|
end
|
1289
|
+
|
1290
|
+
context 'when a session is provided' do
|
1291
|
+
|
1292
|
+
let(:extra_options) do
|
1293
|
+
{ session: session }
|
1294
|
+
end
|
1295
|
+
|
1296
|
+
let(:client) do
|
1297
|
+
collection_invalid_write_concern.client
|
1298
|
+
end
|
1299
|
+
|
1300
|
+
let(:failed_operation) do
|
1301
|
+
bulk_write_invalid_write_concern.execute
|
1302
|
+
end
|
1303
|
+
|
1304
|
+
it_behaves_like 'a failed operation using a session'
|
1305
|
+
end
|
926
1306
|
end
|
927
1307
|
end
|
928
1308
|
end
|
@@ -1701,6 +2081,23 @@ describe Mongo::BulkWrite do
|
|
1701
2081
|
it 'combines the inserted ids' do
|
1702
2082
|
expect(result.inserted_ids.size).to eq(1001)
|
1703
2083
|
end
|
2084
|
+
|
2085
|
+
context 'when a session is provided' do
|
2086
|
+
|
2087
|
+
let(:operation) do
|
2088
|
+
result
|
2089
|
+
end
|
2090
|
+
|
2091
|
+
let(:client) do
|
2092
|
+
authorized_client
|
2093
|
+
end
|
2094
|
+
|
2095
|
+
let(:extra_options) do
|
2096
|
+
{ session: session }
|
2097
|
+
end
|
2098
|
+
|
2099
|
+
it_behaves_like 'an operation using a session'
|
2100
|
+
end
|
1704
2101
|
end
|
1705
2102
|
end
|
1706
2103
|
|
@@ -1719,17 +2116,42 @@ describe Mongo::BulkWrite do
|
|
1719
2116
|
it 'inserts the documents' do
|
1720
2117
|
expect(result.inserted_count).to eq(5)
|
1721
2118
|
end
|
2119
|
+
|
2120
|
+
context 'when a session is provided' do
|
2121
|
+
|
2122
|
+
let(:operation) do
|
2123
|
+
result
|
2124
|
+
end
|
2125
|
+
|
2126
|
+
let(:client) do
|
2127
|
+
authorized_client
|
2128
|
+
end
|
2129
|
+
|
2130
|
+
let(:extra_options) do
|
2131
|
+
{ session: session }
|
2132
|
+
end
|
2133
|
+
|
2134
|
+
it_behaves_like 'an operation using a session'
|
2135
|
+
end
|
1722
2136
|
end
|
1723
2137
|
end
|
1724
2138
|
|
1725
2139
|
context 'when the bulk write is unordered' do
|
1726
2140
|
|
1727
2141
|
let(:bulk_write) do
|
1728
|
-
described_class.new(authorized_collection, requests,
|
2142
|
+
described_class.new(authorized_collection, requests, options)
|
2143
|
+
end
|
2144
|
+
|
2145
|
+
let(:options) do
|
2146
|
+
{ ordered: false }.merge(extra_options)
|
2147
|
+
end
|
2148
|
+
|
2149
|
+
let(:extra_options) do
|
2150
|
+
{}
|
1729
2151
|
end
|
1730
2152
|
|
1731
2153
|
let(:bulk_write_invalid_write_concern) do
|
1732
|
-
described_class.new(collection_invalid_write_concern, requests,
|
2154
|
+
described_class.new(collection_invalid_write_concern, requests, options)
|
1733
2155
|
end
|
1734
2156
|
|
1735
2157
|
it_behaves_like 'an executable bulk write'
|
@@ -1738,11 +2160,19 @@ describe Mongo::BulkWrite do
|
|
1738
2160
|
context 'when the bulk write is ordered' do
|
1739
2161
|
|
1740
2162
|
let(:bulk_write) do
|
1741
|
-
described_class.new(authorized_collection, requests,
|
2163
|
+
described_class.new(authorized_collection, requests, options)
|
2164
|
+
end
|
2165
|
+
|
2166
|
+
let(:options) do
|
2167
|
+
{ ordered: true }.merge(extra_options)
|
2168
|
+
end
|
2169
|
+
|
2170
|
+
let(:extra_options) do
|
2171
|
+
{}
|
1742
2172
|
end
|
1743
2173
|
|
1744
2174
|
let(:bulk_write_invalid_write_concern) do
|
1745
|
-
described_class.new(collection_invalid_write_concern, requests,
|
2175
|
+
described_class.new(collection_invalid_write_concern, requests, options)
|
1746
2176
|
end
|
1747
2177
|
|
1748
2178
|
it_behaves_like 'an executable bulk write'
|