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
@@ -19,16 +19,6 @@ module Mongo
19
19
  # @since 2.1.0
20
20
  module Retryable
21
21
 
22
- # The not master error message.
23
- #
24
- # @since 2.1.0
25
- NOT_MASTER = 'not master'.freeze
26
-
27
- # Could not contact primary error message, seen on stepdowns
28
- #
29
- # @since 2.2.0
30
- COULD_NOT_CONTACT_PRIMARY = 'could not contact primary'.freeze
31
-
32
22
  # Execute a read operation with a retry.
33
23
  #
34
24
  # @api private
@@ -46,21 +36,22 @@ module Mongo
46
36
  # @return [ Result ] The result of the operation.
47
37
  #
48
38
  # @since 2.1.0
49
- def read_with_retry(attempt = 0, &block)
39
+ def read_with_retry
40
+ attempt = 0
50
41
  begin
51
- block.call
52
- rescue Error::SocketError, Error::SocketTimeoutError
53
- retry_operation(&block)
42
+ attempt += 1
43
+ yield
44
+ rescue Error::SocketError, Error::SocketTimeoutError => e
45
+ raise(e) if attempt > cluster.max_read_retries
46
+ log_retry(e)
47
+ cluster.scan!
48
+ retry
54
49
  rescue Error::OperationFailure => e
55
50
  if cluster.sharded? && e.retryable?
56
- if attempt < cluster.max_read_retries
57
- # We don't scan the cluster in this case as Mongos always returns
58
- # ready after a ping no matter what the state behind it is.
59
- sleep(cluster.read_retry_interval)
60
- read_with_retry(attempt + 1, &block)
61
- else
62
- raise e
63
- end
51
+ raise(e) if attempt > cluster.max_read_retries
52
+ log_retry(e)
53
+ sleep(cluster.read_retry_interval)
54
+ retry
64
55
  else
65
56
  raise e
66
57
  end
@@ -83,11 +74,10 @@ module Mongo
83
74
  # @return [ Result ] The result of the operation.
84
75
  #
85
76
  # @since 2.2.6
86
- def read_with_one_retry(&block)
87
- block.call
88
- rescue Error::SocketError,
89
- Error::SocketTimeoutError
90
- block.call
77
+ def read_with_one_retry
78
+ yield
79
+ rescue Error::SocketError, Error::SocketTimeoutError
80
+ yield
91
81
  end
92
82
 
93
83
  # Execute a write operation with a retry.
@@ -107,23 +97,28 @@ module Mongo
107
97
  # @return [ Result ] The result of the operation.
108
98
  #
109
99
  # @since 2.1.0
110
- def write_with_retry(&block)
100
+ def write_with_retry
101
+ attempt = 0
111
102
  begin
112
- block.call
103
+ attempt += 1
104
+ yield
113
105
  rescue Error::OperationFailure => e
114
- if e.message.include?(NOT_MASTER) || e.message.include?(COULD_NOT_CONTACT_PRIMARY)
115
- retry_operation(&block)
106
+ raise(e) if attempt > Cluster::MAX_WRITE_RETRIES
107
+ if e.write_retryable?
108
+ log_retry(e)
109
+ cluster.scan!
110
+ retry
116
111
  else
117
- raise e
112
+ raise(e)
118
113
  end
119
114
  end
120
115
  end
121
116
 
122
117
  private
123
118
 
124
- def retry_operation(&block)
125
- cluster.scan!
126
- block.call
119
+ # Log a warning so that any application slow down is immediately obvious.
120
+ def log_retry(e)
121
+ Logger.logger.warn "Retry due to: #{e.class.name} #{e.message}"
127
122
  end
128
123
  end
129
124
  end
@@ -177,7 +177,7 @@ module Mongo
177
177
  end
178
178
  rescue IO::WaitReadable
179
179
  select_timeout = (deadline - Time.now) if deadline
180
- unless Kernel::select([@socket], nil, [@socket], select_timeout)
180
+ if (select_timeout && select_timeout <= 0) || !Kernel::select([@socket], nil, [@socket], select_timeout)
181
181
  raise Timeout::Error.new("Took more than #{timeout} seconds to receive data.")
182
182
  end
183
183
  retry
@@ -43,6 +43,7 @@ module Mongo
43
43
  def connect!
44
44
  Timeout.timeout(timeout, Error::SocketTimeoutError) do
45
45
  socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
46
+ socket.setsockopt(SOL_SOCKET, SO_KEEPALIVE, true)
46
47
  handle_errors { socket.connect(::Socket.pack_sockaddr_in(port, host)) }
47
48
  self
48
49
  end
@@ -17,5 +17,5 @@ module Mongo
17
17
  # The current version of the driver.
18
18
  #
19
19
  # @since 2.0.0
20
- VERSION = '2.4.1'.freeze
20
+ VERSION = '2.4.2'.freeze
21
21
  end
@@ -20,7 +20,7 @@ describe Mongo::BulkWrite do
20
20
  end
21
21
 
22
22
  let(:collection_invalid_write_concern) do
23
- authorized_collection.client.with(write: { w: (WRITE_CONCERN[:w] + 1) })[authorized_collection.name]
23
+ authorized_collection.client.with(write: INVALID_WRITE_CONCERN)[authorized_collection.name]
24
24
  end
25
25
 
26
26
  let(:collation) do
@@ -680,11 +680,16 @@ describe Mongo::BulkWrite do
680
680
  authorized_collection.insert_one({ _id: 0 })
681
681
  end
682
682
 
683
- it 'replaces the document' do
683
+ it 'replaces the document', if: write_command_enabled? do
684
684
  expect(result.modified_count).to eq(1)
685
685
  expect(authorized_collection.find(_id: 0).first[:name]).to eq('test')
686
686
  end
687
687
 
688
+ it 'replaces the document', unless: write_command_enabled? do
689
+ expect(result.modified_count).to be_nil
690
+ expect(authorized_collection.find(_id: 0).first[:name]).to eq('test')
691
+ end
692
+
688
693
  context 'when there is a write concern error' do
689
694
 
690
695
  context 'when the server version is < 2.6' do
@@ -718,29 +723,33 @@ describe Mongo::BulkWrite do
718
723
  collation: collation }}]
719
724
  end
720
725
 
721
- context 'when the server selected supports collations', if: collation_enabled? do
726
+ context 'when the server selected supports collations' do
722
727
 
723
728
  let!(:result) do
724
729
  bulk_write.execute
725
730
  end
726
731
 
727
- it 'applies the collation' do
732
+ it 'applies the collation', if: collation_enabled? do
728
733
  expect(authorized_collection.find(other: 'pong').count).to eq(1)
729
734
  end
730
735
 
731
- it 'reports the upserted id' do
736
+ it 'reports the upserted id', if: collation_enabled? do
732
737
  expect(result.upserted_ids).to eq([])
733
738
  end
734
739
 
735
- it 'reports the upserted count' do
740
+ it 'reports the upserted count', if: collation_enabled? do
736
741
  expect(result.upserted_count).to eq(0)
737
742
  end
738
743
 
739
- it 'reports the modified count' do
744
+ it 'reports the modified count', if: collation_enabled? && write_command_enabled? do
740
745
  expect(result.modified_count).to eq(1)
741
746
  end
742
747
 
743
- it 'reports the matched count' do
748
+ it 'returns nil for the modified count', if: collation_enabled? && !write_command_enabled? do
749
+ expect(result.modified_count).to be_nil
750
+ end
751
+
752
+ it 'reports the matched count', if: collation_enabled? do
744
753
  expect(result.matched_count).to eq(1)
745
754
  end
746
755
  end
@@ -796,10 +805,14 @@ describe Mongo::BulkWrite do
796
805
  expect(result.upserted_count).to eq(0)
797
806
  end
798
807
 
799
- it 'reports the modified count' do
808
+ it 'reports the modified count', if: write_command_enabled? do
800
809
  expect(result.modified_count).to eq(0)
801
810
  end
802
811
 
812
+ it 'returns nil as the modified count', unless: write_command_enabled? do
813
+ expect(result.modified_count).to be_nil
814
+ end
815
+
803
816
  it 'reports the matched count' do
804
817
  expect(result.matched_count).to eq(0)
805
818
  end
@@ -835,10 +848,14 @@ describe Mongo::BulkWrite do
835
848
  expect(result.upserted_count).to eq(0)
836
849
  end
837
850
 
838
- it 'reports the modified count' do
851
+ it 'reports the modified count', if: write_command_enabled? do
839
852
  expect(result.modified_count).to eq(1)
840
853
  end
841
854
 
855
+ it 'returns nil for the modified count', unless: write_command_enabled? do
856
+ expect(result.modified_count).to be_nil
857
+ end
858
+
842
859
  it 'reports the matched count' do
843
860
  expect(result.matched_count).to eq(1)
844
861
  end
@@ -865,6 +882,10 @@ describe Mongo::BulkWrite do
865
882
  expect(result.modified_count).to eq(0)
866
883
  end
867
884
 
885
+ it 'returns nil for the modified count', unless: write_command_enabled? do
886
+ expect(result.modified_count).to be_nil
887
+ end
888
+
868
889
  it 'reports the matched count' do
869
890
  expect(result.matched_count).to eq(1)
870
891
  end
@@ -925,10 +946,14 @@ describe Mongo::BulkWrite do
925
946
  expect(result.upserted_count).to eq(1)
926
947
  end
927
948
 
928
- it 'reports the modified_count count' do
949
+ it 'reports the modified_count count', if: write_command_enabled? do
929
950
  expect(result.modified_count).to eq(0)
930
951
  end
931
952
 
953
+ it 'returns nil for the modified_count count', unless: write_command_enabled? do
954
+ expect(result.modified_count).to be_nil
955
+ end
956
+
932
957
  it 'reports the matched count' do
933
958
  expect(result.matched_count).to eq(0)
934
959
  end
@@ -971,29 +996,33 @@ describe Mongo::BulkWrite do
971
996
  collation: collation }}]
972
997
  end
973
998
 
974
- context 'when the server selected supports collations', if: collation_enabled? do
999
+ context 'when the server selected supports collations' do
975
1000
 
976
1001
  let!(:result) do
977
1002
  bulk_write.execute
978
1003
  end
979
1004
 
980
- it 'applies the collation' do
1005
+ it 'applies the collation', if: collation_enabled? do
981
1006
  expect(authorized_collection.find(name: 'pong').count).to eq(1)
982
1007
  end
983
1008
 
984
- it 'reports the upserted id' do
1009
+ it 'reports the upserted id', if: collation_enabled? do
985
1010
  expect(result.upserted_ids).to eq([])
986
1011
  end
987
1012
 
988
- it 'reports the upserted count' do
1013
+ it 'reports the upserted count', if: collation_enabled? do
989
1014
  expect(result.upserted_count).to eq(0)
990
1015
  end
991
1016
 
992
- it 'reports the modified count' do
1017
+ it 'reports the modified count', if: collation_enabled? && write_command_enabled? do
993
1018
  expect(result.modified_count).to eq(1)
994
1019
  end
995
1020
 
996
- it 'reports the matched count' do
1021
+ it 'returns nil for the modified count', if: collation_enabled? && !write_command_enabled? do
1022
+ expect(result.modified_count).to be_nil
1023
+ end
1024
+
1025
+ it 'reports the matched count', if: collation_enabled? do
997
1026
  expect(result.matched_count).to eq(1)
998
1027
  end
999
1028
  end
@@ -1049,10 +1078,14 @@ describe Mongo::BulkWrite do
1049
1078
  expect(result.upserted_count).to eq(0)
1050
1079
  end
1051
1080
 
1052
- it 'reports the modified count' do
1081
+ it 'reports the modified count', if: write_command_enabled? do
1053
1082
  expect(result.modified_count).to eq(0)
1054
1083
  end
1055
1084
 
1085
+ it 'returns nil for the modified count', unless: write_command_enabled? do
1086
+ expect(result.modified_count).to be_nil
1087
+ end
1088
+
1056
1089
  it 'reports the matched count' do
1057
1090
  expect(result.matched_count).to eq(0)
1058
1091
  end
@@ -1077,29 +1110,33 @@ describe Mongo::BulkWrite do
1077
1110
  collation: collation }}]
1078
1111
  end
1079
1112
 
1080
- context 'when the server selected supports collations', if: collation_enabled? do
1113
+ context 'when the server selected supports collations' do
1081
1114
 
1082
1115
  let!(:result) do
1083
1116
  bulk_write.execute
1084
1117
  end
1085
1118
 
1086
- it 'applies the collation' do
1119
+ it 'applies the collation', if: collation_enabled? do
1087
1120
  expect(authorized_collection.find(name: 'pong').count).to eq(2)
1088
1121
  end
1089
1122
 
1090
- it 'reports the upserted id' do
1123
+ it 'reports the upserted id', if: collation_enabled? do
1091
1124
  expect(result.upserted_ids).to eq([])
1092
1125
  end
1093
1126
 
1094
- it 'reports the upserted count' do
1127
+ it 'reports the upserted count', if: collation_enabled? do
1095
1128
  expect(result.upserted_count).to eq(0)
1096
1129
  end
1097
1130
 
1098
- it 'reports the modified count' do
1131
+ it 'reports the modified count', if: collation_enabled? && write_command_enabled? do
1099
1132
  expect(result.modified_count).to eq(2)
1100
1133
  end
1101
1134
 
1102
- it 'reports the matched count' do
1135
+ it 'returns nil for the modified count', if: collation_enabled? && !write_command_enabled? do
1136
+ expect(result.modified_count).to be_nil
1137
+ end
1138
+
1139
+ it 'reports the matched count', if: collation_enabled? do
1103
1140
  expect(result.matched_count).to eq(2)
1104
1141
  end
1105
1142
  end
@@ -1160,10 +1197,14 @@ describe Mongo::BulkWrite do
1160
1197
  expect(result.upserted_count).to eq(0)
1161
1198
  end
1162
1199
 
1163
- it 'reports the modified count' do
1200
+ it 'reports the modified count', if: write_command_enabled? do
1164
1201
  expect(result.modified_count).to eq(0)
1165
1202
  end
1166
1203
 
1204
+ it 'returns nil for the modified count', unless: write_command_enabled? do
1205
+ expect(result.modified_count).to be_nil
1206
+ end
1207
+
1167
1208
  it 'reports the matched count' do
1168
1209
  expect(result.matched_count).to eq(0)
1169
1210
  end
@@ -1197,10 +1238,14 @@ describe Mongo::BulkWrite do
1197
1238
  expect(result.upserted_count).to eq(0)
1198
1239
  end
1199
1240
 
1200
- it 'reports the modified count' do
1241
+ it 'reports the modified count', if: write_command_enabled? do
1201
1242
  expect(result.modified_count).to eq(2)
1202
1243
  end
1203
1244
 
1245
+ it 'returns nil for the modified count', unless: write_command_enabled? do
1246
+ expect(result.modified_count).to be_nil
1247
+ end
1248
+
1204
1249
  it 'reports the matched count' do
1205
1250
  expect(result.matched_count).to eq(2)
1206
1251
  end
@@ -1238,8 +1283,8 @@ describe Mongo::BulkWrite do
1238
1283
  expect(result.modified_count).to eq(1)
1239
1284
  end
1240
1285
 
1241
- it 'reports the modified count', unless: write_command_enabled? do
1242
- expect(result.modified_count).to eq(2)
1286
+ it 'returns nil for the modified count', unless: write_command_enabled? do
1287
+ expect(result.modified_count).to be_nil
1243
1288
  end
1244
1289
 
1245
1290
  it 'reports the matched count' do
@@ -1280,19 +1325,28 @@ describe Mongo::BulkWrite do
1280
1325
  bulk_write.execute
1281
1326
  end
1282
1327
 
1283
- it 'updates the document' do
1328
+ it 'updates the document', if: write_command_enabled? do
1284
1329
  expect(result.modified_count).to eq(0)
1285
1330
  expect(authorized_collection.find(name: { '$in' => ['test', 'test1'] }).count).to eq(2)
1286
1331
  end
1287
1332
 
1333
+ it 'updates the document', unless: write_command_enabled? do
1334
+ expect(result.modified_count).to be_nil
1335
+ expect(authorized_collection.find(name: { '$in' => ['test', 'test1'] }).count).to eq(2)
1336
+ end
1337
+
1288
1338
  it 'reports the upserted count' do
1289
1339
  expect(result.upserted_count).to eq(2)
1290
1340
  end
1291
1341
 
1292
- it 'reports the modified count' do
1342
+ it 'reports the modified count', if: write_command_enabled? do
1293
1343
  expect(result.modified_count).to eq(0)
1294
1344
  end
1295
1345
 
1346
+ it 'returns nil for the modified count', unless: write_command_enabled? do
1347
+ expect(result.modified_count).to be_nil
1348
+ end
1349
+
1296
1350
  it 'reports the matched count' do
1297
1351
  expect(result.matched_count).to eq(0)
1298
1352
  end
@@ -1335,8 +1389,8 @@ describe Mongo::BulkWrite do
1335
1389
  expect(result.modified_count).to eq(1)
1336
1390
  end
1337
1391
 
1338
- it 'reports the modified count', unless: write_command_enabled? do
1339
- expect(result.modified_count).to eq(2)
1392
+ it 'returns nil for the modified count', unless: write_command_enabled? do
1393
+ expect(result.modified_count).to be_nil
1340
1394
  end
1341
1395
 
1342
1396
  it 'reports the matched count' do
@@ -1382,29 +1436,33 @@ describe Mongo::BulkWrite do
1382
1436
  collation: collation }}]
1383
1437
  end
1384
1438
 
1385
- context 'when the server selected supports collations', if: collation_enabled? do
1439
+ context 'when the server selected supports collations' do
1386
1440
 
1387
1441
  let!(:result) do
1388
1442
  bulk_write.execute
1389
1443
  end
1390
1444
 
1391
- it 'applies the collation' do
1445
+ it 'applies the collation', if: collation_enabled? do
1392
1446
  expect(authorized_collection.find(name: 'pong').count).to eq(2)
1393
1447
  end
1394
1448
 
1395
- it 'reports the upserted id' do
1449
+ it 'reports the upserted id', if: collation_enabled? do
1396
1450
  expect(result.upserted_ids).to eq([])
1397
1451
  end
1398
1452
 
1399
- it 'reports the upserted count' do
1453
+ it 'reports the upserted count', if: collation_enabled? do
1400
1454
  expect(result.upserted_count).to eq(0)
1401
1455
  end
1402
1456
 
1403
- it 'reports the modified count' do
1457
+ it 'reports the modified count', if: collation_enabled? && write_command_enabled? do
1404
1458
  expect(result.modified_count).to eq(2)
1405
1459
  end
1406
1460
 
1407
- it 'reports the matched count' do
1461
+ it 'returns nil for the modified count', if: collation_enabled? && !write_command_enabled? do
1462
+ expect(result.modified_count).to be_nil
1463
+ end
1464
+
1465
+ it 'reports the matched count', if: collation_enabled? do
1408
1466
  expect(result.matched_count).to eq(2)
1409
1467
  end
1410
1468
  end
@@ -1461,12 +1519,16 @@ describe Mongo::BulkWrite do
1461
1519
  expect(result.upserted_count).to eq(0)
1462
1520
  end
1463
1521
 
1464
- it 'reports the modified count' do
1522
+ it 'reports the modified count', if: write_command_enabled? do
1465
1523
  expect(result.modified_count).to eq(0)
1466
1524
  end
1467
1525
 
1526
+ it 'returns nil for the modified count', unless: write_command_enabled? do
1527
+ expect(result.modified_count).to be_nil
1528
+ end
1529
+
1468
1530
  it 'reports the matched count' do
1469
- expect(result.matched_count).to eq(0)
1531
+ expect(result.matched_count).to be(0)
1470
1532
  end
1471
1533
  end
1472
1534
 
@@ -1496,10 +1558,14 @@ describe Mongo::BulkWrite do
1496
1558
  expect(result.upserted_count).to eq(0)
1497
1559
  end
1498
1560
 
1499
- it 'reports the modified count' do
1561
+ it 'reports the modified count', if: write_command_enabled? do
1500
1562
  expect(result.modified_count).to eq(2)
1501
1563
  end
1502
1564
 
1565
+ it 'returns nil for the modified count', unless: write_command_enabled? do
1566
+ expect(result.modified_count).to be_nil
1567
+ end
1568
+
1503
1569
  it 'reports the matched count' do
1504
1570
  expect(result.matched_count).to eq(2)
1505
1571
  end
@@ -1549,10 +1615,14 @@ describe Mongo::BulkWrite do
1549
1615
  expect(result.matched_count).to eq(0)
1550
1616
  end
1551
1617
 
1552
- it 'reports the modified count' do
1618
+ it 'reports the modified count', if: write_command_enabled? do
1553
1619
  expect(result.modified_count).to eq(0)
1554
1620
  end
1555
1621
 
1622
+ it 'returns nil for the modified count', unless: write_command_enabled? do
1623
+ expect(result.modified_count).to be_nil
1624
+ end
1625
+
1556
1626
  it 'reports the upserted id', if: write_command_enabled? do
1557
1627
  expect(result.upserted_ids).to eq([0])
1558
1628
  end
@@ -1813,7 +1883,7 @@ describe Mongo::BulkWrite do
1813
1883
  ops, :bypass_document_validation => true)
1814
1884
  end
1815
1885
 
1816
- it 'executes successfully' do
1886
+ it 'executes successfully', if: write_command_enabled? do
1817
1887
  expect(result2.modified_count).to eq(2)
1818
1888
  expect(result2.inserted_count).to eq(1)
1819
1889
  end