mongo 2.4.1 → 2.4.2

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 (62) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +3 -3
  5. data/lib/mongo/client.rb +16 -7
  6. data/lib/mongo/cluster.rb +9 -4
  7. data/lib/mongo/cluster/cursor_reaper.rb +1 -0
  8. data/lib/mongo/cluster/topology.rb +1 -1
  9. data/lib/mongo/collection.rb +0 -3
  10. data/lib/mongo/collection/view.rb +12 -5
  11. data/lib/mongo/collection/view/builder/find_command.rb +2 -2
  12. data/lib/mongo/collection/view/readable.rb +4 -4
  13. data/lib/mongo/collection/view/writable.rb +12 -10
  14. data/lib/mongo/cursor.rb +1 -0
  15. data/lib/mongo/error.rb +1 -0
  16. data/lib/mongo/error/invalid_min_pool_size.rb +35 -0
  17. data/lib/mongo/error/operation_failure.rb +24 -5
  18. data/lib/mongo/operation/write/bulk/update/result.rb +1 -10
  19. data/lib/mongo/operation/write/update/result.rb +26 -7
  20. data/lib/mongo/retryable.rb +30 -35
  21. data/lib/mongo/socket.rb +1 -1
  22. data/lib/mongo/socket/tcp.rb +1 -0
  23. data/lib/mongo/version.rb +1 -1
  24. data/spec/mongo/bulk_write_spec.rb +113 -43
  25. data/spec/mongo/client_spec.rb +253 -0
  26. data/spec/mongo/cluster/topology_spec.rb +37 -0
  27. data/spec/mongo/cluster_spec.rb +1 -1
  28. data/spec/mongo/collection/view/aggregation_spec.rb +2 -2
  29. data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
  30. data/spec/mongo/collection_spec.rb +55 -19
  31. data/spec/mongo/command_monitoring_spec.rb +1 -1
  32. data/spec/mongo/database_spec.rb +5 -5
  33. data/spec/mongo/grid/stream/write_spec.rb +2 -2
  34. data/spec/mongo/index/view_spec.rb +5 -5
  35. data/spec/mongo/max_staleness_spec.rb +0 -4
  36. data/spec/mongo/operation/write/update_spec.rb +15 -3
  37. data/spec/mongo/retryable_spec.rb +26 -22
  38. data/spec/mongo/server/connection_spec.rb +26 -0
  39. data/spec/mongo/shell_examples_spec.rb +981 -0
  40. data/spec/mongo/socket/ssl_spec.rb +51 -18
  41. data/spec/spec_helper.rb +26 -16
  42. data/spec/support/authorization.rb +38 -16
  43. data/spec/support/connection_string.rb +3 -3
  44. data/spec/support/crud.rb +38 -10
  45. data/spec/support/crud/write.rb +6 -3
  46. data/spec/support/crud_tests/write/findOneAndReplace-upsert.yml +48 -4
  47. data/spec/support/crud_tests/write/findOneAndReplace-upsert_pre_2.6.yml +88 -0
  48. data/spec/support/crud_tests/write/findOneAndReplace.yml +0 -29
  49. data/spec/support/crud_tests/write/findOneAndUpdate.yml +4 -1
  50. data/spec/support/crud_tests/write/replaceOne-collation.yml +1 -0
  51. data/spec/support/crud_tests/write/replaceOne-pre_2.6.yml +98 -0
  52. data/spec/support/crud_tests/write/replaceOne.yml +21 -5
  53. data/spec/support/crud_tests/write/updateMany-collation.yml +1 -0
  54. data/spec/support/crud_tests/write/updateMany-pre_2.6.yml +86 -0
  55. data/spec/support/crud_tests/write/updateMany.yml +5 -0
  56. data/spec/support/crud_tests/write/updateOne-collation.yml +1 -0
  57. data/spec/support/crud_tests/write/updateOne-pre_2.6.yml +83 -0
  58. data/spec/support/crud_tests/write/updateOne.yml +7 -2
  59. data/spec/support/gridfs.rb +1 -0
  60. metadata +13 -4
  61. metadata.gz.sig +2 -1
  62. data/spec/support/helpers.rb +0 -140
@@ -218,6 +218,78 @@ describe Mongo::Client do
218
218
 
219
219
  context 'when providing options' do
220
220
 
221
+ context 'when ssl options are provided' do
222
+
223
+ let(:options) do
224
+ {
225
+ :ssl => true,
226
+ :ssl_ca_cert => CA_PEM,
227
+ :ssl_ca_cert_string => 'ca cert string',
228
+ :ssl_ca_cert_object => 'ca cert object',
229
+ :ssl_cert => CLIENT_CERT_PEM,
230
+ :ssl_cert_string => 'cert string',
231
+ :ssl_cert_object => 'cert object',
232
+ :ssl_key => CLIENT_KEY_PEM,
233
+ :ssl_key_string => 'key string',
234
+ :ssl_key_object => 'key object',
235
+ :ssl_key_pass_phrase => 'passphrase',
236
+ :ssl_verify => true
237
+ }
238
+ end
239
+
240
+ let(:client) do
241
+ described_class.new(['127.0.0.1:27017'], options)
242
+ end
243
+
244
+ it 'sets the ssl option' do
245
+ expect(client.options[:ssl]).to eq(options[:ssl])
246
+ end
247
+
248
+ it 'sets the ssl_ca_cert option' do
249
+ expect(client.options[:ssl_ca_cert]).to eq(options[:ssl_ca_cert])
250
+ end
251
+
252
+ it 'sets the ssl_ca_cert_string option' do
253
+ expect(client.options[:ssl_ca_cert_string]).to eq(options[:ssl_ca_cert_string])
254
+ end
255
+
256
+ it 'sets the ssl_ca_cert_object option' do
257
+ expect(client.options[:ssl_ca_cert_object]).to eq(options[:ssl_ca_cert_object])
258
+ end
259
+
260
+ it 'sets the ssl_cert option' do
261
+ expect(client.options[:ssl_cert]).to eq(options[:ssl_cert])
262
+ end
263
+
264
+ it 'sets the ssl_cert_string option' do
265
+ expect(client.options[:ssl_cert_string]).to eq(options[:ssl_cert_string])
266
+ end
267
+
268
+ it 'sets the ssl_cert_object option' do
269
+ expect(client.options[:ssl_cert_object]).to eq(options[:ssl_cert_object])
270
+ end
271
+
272
+ it 'sets the ssl_key option' do
273
+ expect(client.options[:ssl_key]).to eq(options[:ssl_key])
274
+ end
275
+
276
+ it 'sets the ssl_key_string option' do
277
+ expect(client.options[:ssl_key_string]).to eq(options[:ssl_key_string])
278
+ end
279
+
280
+ it 'sets the ssl_key_object option' do
281
+ expect(client.options[:ssl_key_object]).to eq(options[:ssl_key_object])
282
+ end
283
+
284
+ it 'sets the ssl_key_pass_phrase option' do
285
+ expect(client.options[:ssl_key_pass_phrase]).to eq(options[:ssl_key_pass_phrase])
286
+ end
287
+
288
+ it 'sets the ssl_verify option' do
289
+ expect(client.options[:ssl_verify]).to eq(options[:ssl_verify])
290
+ end
291
+ end
292
+
221
293
  context 'when no database is provided' do
222
294
 
223
295
  let(:client) do
@@ -272,6 +344,106 @@ describe Mongo::Client do
272
344
  end
273
345
  end
274
346
 
347
+ context 'when min_pool_size is provided' do
348
+
349
+ let(:client) do
350
+ described_class.new(['127.0.0.1:27017'], options)
351
+ end
352
+
353
+ context 'when max_pool_size is provided' do
354
+
355
+ context 'when the min_pool_size is greater than the max_pool_size' do
356
+
357
+ let(:options) do
358
+ {
359
+ :min_pool_size => 20,
360
+ :max_pool_size => 10
361
+ }
362
+ end
363
+
364
+ it 'raises an Exception' do
365
+ expect {
366
+ client
367
+ }.to raise_exception(Mongo::Error::InvalidMinPoolSize)
368
+ end
369
+ end
370
+
371
+ context 'when the min_pool_size is less than the max_pool_size' do
372
+
373
+ let(:options) do
374
+ {
375
+ :min_pool_size => 10,
376
+ :max_pool_size => 20
377
+ }
378
+ end
379
+
380
+ it 'sets the option' do
381
+ expect(client.options[:min_pool_size]).to eq(options[:min_pool_size])
382
+ expect(client.options[:max_pool_size]).to eq(options[:max_pool_size])
383
+ end
384
+ end
385
+
386
+ context 'when the min_pool_size is equal to the max_pool_size' do
387
+
388
+ let(:options) do
389
+ {
390
+ :min_pool_size => 10,
391
+ :max_pool_size => 10
392
+ }
393
+ end
394
+
395
+ it 'sets the option' do
396
+ expect(client.options[:min_pool_size]).to eq(options[:min_pool_size])
397
+ expect(client.options[:max_pool_size]).to eq(options[:max_pool_size])
398
+ end
399
+ end
400
+ end
401
+
402
+ context 'when max_pool_size is not provided' do
403
+
404
+ context 'when the min_pool_size is greater than the default max_pool_size' do
405
+
406
+ let(:options) do
407
+ {
408
+ :min_pool_size => 10
409
+ }
410
+ end
411
+
412
+ it 'raises an Exception' do
413
+ expect {
414
+ client
415
+ }.to raise_exception(Mongo::Error::InvalidMinPoolSize)
416
+ end
417
+ end
418
+
419
+ context 'when the min_pool_size is less than the default max_pool_size' do
420
+
421
+ let(:options) do
422
+ {
423
+ :min_pool_size => 3
424
+ }
425
+ end
426
+
427
+ it 'sets the option' do
428
+ expect(client.options[:min_pool_size]).to eq(options[:min_pool_size])
429
+ end
430
+ end
431
+
432
+ context 'when the min_pool_size is equal to the max_pool_size' do
433
+
434
+ let(:options) do
435
+ {
436
+ :min_pool_size => Mongo::Server::ConnectionPool::Queue::MAX_SIZE
437
+ }
438
+ end
439
+
440
+ it 'sets the option' do
441
+ expect(client.options[:min_pool_size]).to eq(options[:min_pool_size])
442
+ end
443
+ end
444
+ end
445
+ end
446
+
275
447
  context 'when platform details are specified' do
276
448
 
277
449
  let(:app_metadata) do
@@ -360,6 +532,87 @@ describe Mongo::Client do
360
532
  it 'sets the options' do
361
533
  expect(client.options).to eq(expected_options)
362
534
  end
535
+
536
+ context 'when min_pool_size is provided' do
537
+
538
+ context 'when max_pool_size is provided' do
539
+
540
+ context 'when the min_pool_size is greater than the max_pool_size' do
541
+
542
+ let(:uri) do
543
+ 'mongodb://127.0.0.1:27017/?minPoolSize=20&maxPoolSize=10'
544
+ end
545
+
546
+ it 'raises an Exception' do
547
+ expect {
548
+ client
549
+ }.to raise_exception(Mongo::Error::InvalidMinPoolSize)
550
+ end
551
+ end
552
+
553
+ context 'when the min_pool_size is less than the max_pool_size' do
554
+
555
+ let(:uri) do
556
+ 'mongodb://127.0.0.1:27017/?minPoolSize=10&maxPoolSize=20'
557
+ end
558
+
559
+ it 'sets the option' do
560
+ expect(client.options[:min_pool_size]).to eq(10)
561
+ expect(client.options[:max_pool_size]).to eq(20)
562
+ end
563
+ end
564
+
565
+ context 'when the min_pool_size is equal to the max_pool_size' do
566
+
567
+ let(:uri) do
568
+ 'mongodb://127.0.0.1:27017/?minPoolSize=10&maxPoolSize=10'
569
+ end
570
+
571
+ it 'sets the option' do
572
+ expect(client.options[:min_pool_size]).to eq(10)
573
+ expect(client.options[:max_pool_size]).to eq(10)
574
+ end
575
+ end
576
+ end
577
+
578
+ context 'when max_pool_size is not provided' do
579
+
580
+ context 'when the min_pool_size is greater than the default max_pool_size' do
581
+
582
+ let(:uri) do
583
+ 'mongodb://127.0.0.1:27017/?minPoolSize=10'
584
+ end
585
+
586
+ it 'raises an Exception' do
587
+ expect {
588
+ client
589
+ }.to raise_exception(Mongo::Error::InvalidMinPoolSize)
590
+ end
591
+ end
592
+
593
+ context 'when the min_pool_size is less than the default max_pool_size' do
594
+
595
+ let(:uri) do
596
+ 'mongodb://127.0.0.1:27017/?minPoolSize=3'
597
+ end
598
+
599
+ it 'sets the option' do
600
+ expect(client.options[:min_pool_size]).to eq(3)
601
+ end
602
+ end
603
+
604
+ context 'when the min_pool_size is equal to the max_pool_size' do
605
+
606
+ let(:uri) do
607
+ 'mongodb://127.0.0.1:27017/?minPoolSize=5'
608
+ end
609
+
610
+ it 'sets the option' do
611
+ expect(client.options[:min_pool_size]).to eq(5)
612
+ end
613
+ end
614
+ end
615
+ end
363
616
  end
364
617
 
365
618
  context 'when options are provided not in the string' do
@@ -17,6 +17,17 @@ describe Mongo::Cluster::Topology do
17
17
  it 'returns a replica set topology' do
18
18
  expect(topology).to be_a(Mongo::Cluster::Topology::ReplicaSet)
19
19
  end
20
+
21
+ context 'when the option is a String (due to YAML parsing)' do
22
+
23
+ let(:topology) do
24
+ described_class.initial([ 'a' ], monitoring, connect: 'replica_set')
25
+ end
26
+
27
+ it 'returns a replica set topology' do
28
+ expect(topology).to be_a(Mongo::Cluster::Topology::ReplicaSet)
29
+ end
30
+ end
20
31
  end
21
32
 
22
33
  context 'when provided a single option' do
@@ -32,6 +43,21 @@ describe Mongo::Cluster::Topology do
32
43
  it 'sets the seed on the topology' do
33
44
  expect(topology.seed).to eq('a')
34
45
  end
46
+
47
+ context 'when the option is a String (due to YAML parsing)' do
48
+
49
+ let(:topology) do
50
+ described_class.initial([ 'a' ], monitoring, connect: 'direct')
51
+ end
52
+
53
+ it 'returns a single topology' do
54
+ expect(topology).to be_a(Mongo::Cluster::Topology::Single)
55
+ end
56
+
57
+ it 'sets the seed on the topology' do
58
+ expect(topology.seed).to eq('a')
59
+ end
60
+ end
35
61
  end
36
62
 
37
63
  context 'when provided a sharded option' do
@@ -43,6 +69,17 @@ describe Mongo::Cluster::Topology do
43
69
  it 'returns a sharded topology' do
44
70
  expect(topology).to be_a(Mongo::Cluster::Topology::Sharded)
45
71
  end
72
+
73
+ context 'when the option is a String (due to YAML parsing)' do
74
+
75
+ let(:topology) do
76
+ described_class.initial([ 'a' ], monitoring, connect: 'sharded')
77
+ end
78
+
79
+ it 'returns a sharded topology' do
80
+ expect(topology).to be_a(Mongo::Cluster::Topology::Sharded)
81
+ end
82
+ end
46
83
  end
47
84
 
48
85
  context 'when provided no option' do
@@ -113,7 +113,7 @@ describe Mongo::Cluster do
113
113
  context 'when the option is not provided' do
114
114
 
115
115
  let(:cluster) do
116
- described_class.new([ '127.0.0.1:27017' ], monitoring, TEST_OPTIONS.dup.delete_if { |k| k == :replica_set })
116
+ described_class.new([ '127.0.0.1:27017' ], monitoring, TEST_OPTIONS.merge(connect: :direct).delete_if { |k| k == :replica_set })
117
117
  end
118
118
 
119
119
  it 'returns nil' do
@@ -151,7 +151,7 @@ describe Mongo::Collection::View::Aggregation do
151
151
  context 'when the view has a write concern' do
152
152
 
153
153
  let(:collection) do
154
- authorized_collection.with(write: { w: WRITE_CONCERN[:w]+1 })
154
+ authorized_collection.with(write: INVALID_WRITE_CONCERN)
155
155
  end
156
156
 
157
157
  let(:view) do
@@ -532,7 +532,7 @@ describe Mongo::Collection::View::Aggregation do
532
532
  context 'when the view has a write concern' do
533
533
 
534
534
  let(:collection) do
535
- authorized_collection.with(write: { w: WRITE_CONCERN[:w]+1 })
535
+ authorized_collection.with(write: INVALID_WRITE_CONCERN)
536
536
  end
537
537
 
538
538
  let(:view) do
@@ -390,7 +390,7 @@ describe Mongo::Collection::View::MapReduce do
390
390
  context 'when the view has a write concern' do
391
391
 
392
392
  let(:collection) do
393
- authorized_collection.with(write: { w: WRITE_CONCERN[:w]+1 })
393
+ authorized_collection.with(write: INVALID_WRITE_CONCERN)
394
394
  end
395
395
 
396
396
  let(:view) do
@@ -7,7 +7,7 @@ describe Mongo::Collection do
7
7
  end
8
8
 
9
9
  let(:collection_invalid_write_concern) do
10
- authorized_collection.client.with(write: { w: (WRITE_CONCERN[:w] + 1) })[authorized_collection.name]
10
+ authorized_collection.client.with(write: INVALID_WRITE_CONCERN)[authorized_collection.name]
11
11
  end
12
12
 
13
13
  let(:collection_with_validator) do
@@ -97,7 +97,7 @@ describe Mongo::Collection do
97
97
  describe '#with' do
98
98
 
99
99
  let(:client) do
100
- Mongo::Client.new(ADDRESSES)
100
+ Mongo::Client.new(ADDRESSES, TEST_OPTIONS)
101
101
  end
102
102
 
103
103
  let(:database) do
@@ -129,7 +129,7 @@ describe Mongo::Collection do
129
129
  context 'when the client has a server selection timeout setting' do
130
130
 
131
131
  let(:client) do
132
- Mongo::Client.new(ADDRESSES, server_selection_timeout: 2)
132
+ Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(server_selection_timeout: 2))
133
133
  end
134
134
 
135
135
  it 'passes the the server_selection_timeout to the cluster' do
@@ -140,7 +140,7 @@ describe Mongo::Collection do
140
140
  context 'when the client has a read preference set' do
141
141
 
142
142
  let(:client) do
143
- Mongo::Client.new(ADDRESSES, read: { mode: :primary_preferred })
143
+ Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(read: { mode: :primary_preferred }))
144
144
  end
145
145
 
146
146
  it 'sets the new read options on the new collection' do
@@ -152,7 +152,7 @@ describe Mongo::Collection do
152
152
  context 'when the client has a read preference and server selection timeout set' do
153
153
 
154
154
  let(:client) do
155
- Mongo::Client.new(ADDRESSES, read: { mode: :primary_preferred }, server_selection_timeout: 2)
155
+ Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(read: { mode: :primary_preferred }, server_selection_timeout: 2))
156
156
  end
157
157
 
158
158
  it 'sets the new read options on the new collection' do
@@ -182,7 +182,7 @@ describe Mongo::Collection do
182
182
  context 'when the client has a write concern set' do
183
183
 
184
184
  let(:client) do
185
- Mongo::Client.new(ADDRESSES, write: { w: 10 })
185
+ Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(write: { w: 10 }))
186
186
  end
187
187
 
188
188
  it 'sets the new write options on the new collection' do
@@ -215,7 +215,7 @@ describe Mongo::Collection do
215
215
  context 'when the client has a server selection timeout setting' do
216
216
 
217
217
  let(:client) do
218
- Mongo::Client.new(ADDRESSES, server_selection_timeout: 2)
218
+ Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(server_selection_timeout: 2))
219
219
  end
220
220
 
221
221
  it 'passes the server_selection_timeout setting to the cluster' do
@@ -226,7 +226,7 @@ describe Mongo::Collection do
226
226
  context 'when the client has a read preference set' do
227
227
 
228
228
  let(:client) do
229
- Mongo::Client.new(ADDRESSES, read: { mode: :primary_preferred })
229
+ Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(read: { mode: :primary_preferred }))
230
230
  end
231
231
 
232
232
  it 'sets the new read options on the new collection' do
@@ -422,7 +422,7 @@ describe Mongo::Collection do
422
422
 
423
423
  let(:options) do
424
424
  {
425
- write: { w: WRITE_CONCERN[:w] + 1}
425
+ write: INVALID_WRITE_CONCERN
426
426
  }
427
427
  end
428
428
 
@@ -569,7 +569,7 @@ describe Mongo::Collection do
569
569
 
570
570
  let(:write_options) do
571
571
  {
572
- write: { w: WRITE_CONCERN[:w] + 1}
572
+ write: INVALID_WRITE_CONCERN
573
573
  }
574
574
  end
575
575
 
@@ -1819,10 +1819,14 @@ describe Mongo::Collection do
1819
1819
  authorized_collection.find(field: 'testing').first
1820
1820
  end
1821
1821
 
1822
- it 'updates the first matching document in the collection' do
1822
+ it 'updates the first matching document in the collection', if: write_command_enabled? do
1823
1823
  expect(response.modified_count).to eq(1)
1824
1824
  end
1825
1825
 
1826
+ it 'does not return modified count', unless: write_command_enabled? do
1827
+ expect(response.modified_count).to eq(nil)
1828
+ end
1829
+
1826
1830
  it 'updates the documents in the collection' do
1827
1831
  expect(updated[:field]).to eq('testing')
1828
1832
  end
@@ -1838,10 +1842,14 @@ describe Mongo::Collection do
1838
1842
  authorized_collection.find(field: 'test1').to_a
1839
1843
  end
1840
1844
 
1841
- it 'reports that no documents were written' do
1845
+ it 'reports that no documents were written', if: write_command_enabled? do
1842
1846
  expect(response.modified_count).to eq(0)
1843
1847
  end
1844
1848
 
1849
+ it 'does not return modified count', unless: write_command_enabled? do
1850
+ expect(response.modified_count).to eq(nil)
1851
+ end
1852
+
1845
1853
  it 'does not insert the document' do
1846
1854
  expect(updated).to be_empty
1847
1855
  end
@@ -1876,10 +1884,14 @@ describe Mongo::Collection do
1876
1884
  authorized_collection.find(field: 'test1').to_a
1877
1885
  end
1878
1886
 
1879
- it 'reports that no documents were written' do
1887
+ it 'reports that no documents were written', if: write_command_enabled? do
1880
1888
  expect(response.modified_count).to eq(0)
1881
1889
  end
1882
1890
 
1891
+ it 'does not return modified count', unless: write_command_enabled? do
1892
+ expect(response.modified_count).to eq(nil)
1893
+ end
1894
+
1883
1895
  it 'does not insert the document' do
1884
1896
  expect(updated).to be_empty
1885
1897
  end
@@ -2073,10 +2085,14 @@ describe Mongo::Collection do
2073
2085
  authorized_collection.find(field: 'testing').to_a.last
2074
2086
  end
2075
2087
 
2076
- it 'returns the number updated' do
2088
+ it 'returns the number updated', if: write_command_enabled? do
2077
2089
  expect(response.modified_count).to eq(2)
2078
2090
  end
2079
2091
 
2092
+ it 'does not return modified count', unless: write_command_enabled? do
2093
+ expect(response.modified_count).to eq(nil)
2094
+ end
2095
+
2080
2096
  it 'updates the documents in the collection' do
2081
2097
  expect(updated[:field]).to eq('testing')
2082
2098
  end
@@ -2093,10 +2109,14 @@ describe Mongo::Collection do
2093
2109
  authorized_collection.find.to_a
2094
2110
  end
2095
2111
 
2096
- it 'reports that no documents were updated' do
2112
+ it 'reports that no documents were updated', if: write_command_enabled? do
2097
2113
  expect(response.modified_count).to eq(0)
2098
2114
  end
2099
2115
 
2116
+ it 'does not return modified count', unless: write_command_enabled? do
2117
+ expect(response.modified_count).to eq(nil)
2118
+ end
2119
+
2100
2120
  it 'updates no documents in the collection' do
2101
2121
  expect(updated).to be_empty
2102
2122
  end
@@ -2132,10 +2152,14 @@ describe Mongo::Collection do
2132
2152
  authorized_collection.find.to_a
2133
2153
  end
2134
2154
 
2135
- it 'reports that no documents were updated' do
2155
+ it 'reports that no documents were updated', if: write_command_enabled? do
2136
2156
  expect(response.modified_count).to eq(0)
2137
2157
  end
2138
2158
 
2159
+ it 'does not return modified count', unless: write_command_enabled? do
2160
+ expect(response.modified_count).to eq(nil)
2161
+ end
2162
+
2139
2163
  it 'updates no documents in the collection' do
2140
2164
  expect(updated).to be_empty
2141
2165
  end
@@ -2333,10 +2357,14 @@ describe Mongo::Collection do
2333
2357
  authorized_collection.find(field: 'testing').first
2334
2358
  end
2335
2359
 
2336
- it 'updates the first matching document in the collection' do
2360
+ it 'updates the first matching document in the collection', if: write_command_enabled? do
2337
2361
  expect(response.modified_count).to eq(1)
2338
2362
  end
2339
2363
 
2364
+ it 'does not return modified count', unless: write_command_enabled? do
2365
+ expect(response.modified_count).to eq(nil)
2366
+ end
2367
+
2340
2368
  it 'updates the documents in the collection' do
2341
2369
  expect(updated[:field]).to eq('testing')
2342
2370
  end
@@ -2353,10 +2381,14 @@ describe Mongo::Collection do
2353
2381
  authorized_collection.find.to_a
2354
2382
  end
2355
2383
 
2356
- it 'reports that no documents were updated' do
2384
+ it 'reports that no documents were updated', if: write_command_enabled? do
2357
2385
  expect(response.modified_count).to eq(0)
2358
2386
  end
2359
2387
 
2388
+ it 'does not return modified count', unless: write_command_enabled? do
2389
+ expect(response.modified_count).to eq(nil)
2390
+ end
2391
+
2360
2392
  it 'updates no documents in the collection' do
2361
2393
  expect(updated).to be_empty
2362
2394
  end
@@ -2392,10 +2424,14 @@ describe Mongo::Collection do
2392
2424
  authorized_collection.find.to_a
2393
2425
  end
2394
2426
 
2395
- it 'reports that no documents were updated' do
2427
+ it 'reports that no documents were updated', if: write_command_enabled? do
2396
2428
  expect(response.modified_count).to eq(0)
2397
2429
  end
2398
2430
 
2431
+ it 'does not return modified count', unless: write_command_enabled? do
2432
+ expect(response.modified_count).to eq(nil)
2433
+ end
2434
+
2399
2435
  it 'updates no documents in the collection' do
2400
2436
  expect(updated).to be_empty
2401
2437
  end