mongo 2.7.0 → 2.7.1

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 (125) 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 +39 -14
  5. data/Rakefile +1 -0
  6. data/lib/mongo/auth.rb +4 -1
  7. data/lib/mongo/client.rb +4 -3
  8. data/lib/mongo/cluster.rb +1 -1
  9. data/lib/mongo/collection/view/readable.rb +5 -2
  10. data/lib/mongo/database.rb +1 -0
  11. data/lib/mongo/error/invalid_server_preference.rb +1 -0
  12. data/lib/mongo/error/operation_failure.rb +10 -0
  13. data/lib/mongo/error/parser.rb +10 -0
  14. data/lib/mongo/event.rb +1 -2
  15. data/lib/mongo/operation/result.rb +4 -1
  16. data/lib/mongo/operation/shared/executable_transaction_label.rb +3 -1
  17. data/lib/mongo/operation/shared/sessions_supported.rb +1 -1
  18. data/lib/mongo/protocol/msg.rb +1 -1
  19. data/lib/mongo/protocol/query.rb +2 -2
  20. data/lib/mongo/retryable.rb +20 -6
  21. data/lib/mongo/server.rb +6 -0
  22. data/lib/mongo/server/connection.rb +4 -4
  23. data/lib/mongo/server/monitor/connection.rb +9 -5
  24. data/lib/mongo/server_selector/selectable.rb +86 -32
  25. data/lib/mongo/session.rb +98 -15
  26. data/lib/mongo/version.rb +1 -1
  27. data/spec/README.md +85 -0
  28. data/spec/integration/bulk_insert_spec.rb +1 -1
  29. data/spec/integration/change_stream_examples_spec.rb +3 -1
  30. data/spec/integration/change_stream_spec.rb +10 -14
  31. data/spec/integration/client_construction_spec.rb +1 -0
  32. data/spec/integration/command_monitoring_spec.rb +37 -1
  33. data/spec/integration/command_spec.rb +141 -0
  34. data/spec/integration/connection_spec.rb +4 -2
  35. data/spec/integration/cursor_reaping_spec.rb +1 -1
  36. data/spec/integration/docs_examples_spec.rb +1 -1
  37. data/spec/integration/retryable_writes_spec.rb +33 -42
  38. data/spec/integration/server_description_spec.rb +3 -3
  39. data/spec/integration/server_selector_spec.rb +79 -0
  40. data/spec/lite_spec_helper.rb +4 -2
  41. data/spec/mongo/address_spec.rb +8 -0
  42. data/spec/mongo/auth/cr_spec.rb +5 -2
  43. data/spec/mongo/auth/invalid_mechanism_spec.rb +11 -0
  44. data/spec/mongo/auth/scram/conversation_spec.rb +3 -2
  45. data/spec/mongo/auth/scram/negotiation_spec.rb +1 -2
  46. data/spec/mongo/auth/scram_spec.rb +11 -6
  47. data/spec/mongo/auth/user/view_spec.rb +13 -6
  48. data/spec/mongo/bulk_write_spec.rb +81 -104
  49. data/spec/mongo/client_construction_spec.rb +18 -7
  50. data/spec/mongo/client_spec.rb +11 -7
  51. data/spec/mongo/cluster_spec.rb +30 -1
  52. data/spec/mongo/collection/view/aggregation_spec.rb +18 -10
  53. data/spec/mongo/collection/view/change_stream_spec.rb +28 -8
  54. data/spec/mongo/collection/view/map_reduce_spec.rb +24 -10
  55. data/spec/mongo/collection/view/readable_spec.rb +37 -19
  56. data/spec/mongo/collection/view/writable_spec.rb +64 -32
  57. data/spec/mongo/collection/view_spec.rb +4 -2
  58. data/spec/mongo/collection_spec.rb +163 -73
  59. data/spec/mongo/cursor_spec.rb +5 -2
  60. data/spec/mongo/database_spec.rb +41 -19
  61. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  62. data/spec/mongo/error/parser_spec.rb +29 -0
  63. data/spec/mongo/grid/stream/write_spec.rb +2 -1
  64. data/spec/mongo/index/view_spec.rb +42 -24
  65. data/spec/mongo/operation/delete/op_msg_spec.rb +11 -7
  66. data/spec/mongo/operation/insert/op_msg_spec.rb +10 -6
  67. data/spec/mongo/operation/update/op_msg_spec.rb +10 -6
  68. data/spec/mongo/protocol/compressed_spec.rb +1 -1
  69. data/spec/mongo/protocol/msg_spec.rb +1 -1
  70. data/spec/mongo/server/app_metadata_spec.rb +2 -1
  71. data/spec/mongo/server/connection_auth_spec.rb +1 -1
  72. data/spec/mongo/server/monitor/connection_spec.rb +42 -0
  73. data/spec/mongo/server_selector_spec.rb +17 -0
  74. data/spec/mongo/server_spec.rb +110 -0
  75. data/spec/mongo/session/session_pool_spec.rb +1 -1
  76. data/spec/mongo/session_spec.rb +1 -1
  77. data/spec/mongo/session_transaction_spec.rb +162 -1
  78. data/spec/mongo/socket/ssl_spec.rb +14 -7
  79. data/spec/mongo/uri/srv_protocol_spec.rb +41 -34
  80. data/spec/spec_helper.rb +3 -191
  81. data/spec/spec_tests/change_streams_spec.rb +3 -6
  82. data/spec/spec_tests/data/transactions/abort.yml +3 -1
  83. data/spec/spec_tests/data/transactions/commit.yml +4 -3
  84. data/spec/spec_tests/data/transactions/error-labels.yml +17 -13
  85. data/spec/spec_tests/data/transactions/read-concern.yml +611 -0
  86. data/spec/spec_tests/data/transactions/retryable-commit.yml +126 -21
  87. data/spec/spec_tests/data/transactions_api/callback-aborts.yml +42 -39
  88. data/spec/spec_tests/data/transactions_api/callback-commits.yml +52 -50
  89. data/spec/spec_tests/data/transactions_api/callback-retry.yml +33 -31
  90. data/spec/spec_tests/data/transactions_api/commit-retry.yml +42 -39
  91. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +13 -12
  92. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +15 -26
  93. data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +25 -33
  94. data/spec/spec_tests/data/transactions_api/commit.yml +44 -42
  95. data/spec/spec_tests/data/transactions_api/transaction-options.yml +25 -23
  96. data/spec/spec_tests/max_staleness_spec.rb +2 -0
  97. data/spec/spec_tests/retryable_writes_spec.rb +2 -6
  98. data/spec/spec_tests/sdam_spec.rb +2 -0
  99. data/spec/spec_tests/server_selection_spec.rb +3 -0
  100. data/spec/spec_tests/transactions_api_spec.rb +7 -1
  101. data/spec/spec_tests/transactions_spec.rb +6 -0
  102. data/spec/spec_tests/uri_options_spec.rb +4 -26
  103. data/spec/support/certificates/ca.pem +21 -16
  104. data/spec/support/certificates/client.pem +90 -90
  105. data/spec/support/certificates/client_cert.pem +21 -20
  106. data/spec/support/certificates/client_key.pem +27 -28
  107. data/spec/support/certificates/client_key_encrypted.pem +26 -26
  108. data/spec/support/certificates/crl.pem +10 -8
  109. data/spec/support/certificates/crl_client_revoked.pem +11 -10
  110. data/spec/support/certificates/server.pem +48 -33
  111. data/spec/support/change_streams.rb +12 -32
  112. data/spec/support/client_registry.rb +12 -1
  113. data/spec/support/cluster_config.rb +48 -2
  114. data/spec/support/common_shortcuts.rb +73 -7
  115. data/spec/support/connection_string.rb +0 -3
  116. data/spec/support/constraints.rb +87 -22
  117. data/spec/support/crud.rb +2 -1
  118. data/spec/support/shared/server_selector.rb +0 -28
  119. data/spec/support/shared/session.rb +25 -14
  120. data/spec/support/transactions.rb +4 -8
  121. data/spec/support/transactions/operation.rb +26 -4
  122. data/spec/support/transactions/verifier.rb +5 -2
  123. metadata +496 -488
  124. metadata.gz.sig +5 -2
  125. data/spec/support/certificates/password_protected.pem +0 -51
@@ -190,9 +190,14 @@ describe Mongo::Client do
190
190
  expect(client.cluster.app_metadata.send(:document)[:compression]).to eq(options[:compressors])
191
191
  end
192
192
 
193
- it 'uses compression for messages', if: testing_compression? do
194
- expect(Mongo::Protocol::Compressed).to receive(:new).and_call_original
195
- client[TEST_COLL].find({}, limit: 1).first
193
+ context 'when server supports compression' do
194
+ require_compression
195
+ min_server_fcv '3.6'
196
+
197
+ it 'uses compression for messages' do
198
+ expect(Mongo::Protocol::Compressed).to receive(:new).and_call_original
199
+ client[TEST_COLL].find({}, limit: 1).first
200
+ end
196
201
  end
197
202
 
198
203
  it 'does not use compression for authentication messages' do
@@ -218,7 +223,9 @@ describe Mongo::Client do
218
223
  expect(client.cluster.app_metadata.send(:document)[:compression]).to eq([])
219
224
  end
220
225
 
221
- context 'when one supported compressor and one unsupported compressor are provided', if: compression_enabled? do
226
+ context 'when one supported compressor and one unsupported compressor are provided' do
227
+ require_compression
228
+ min_server_fcv '3.6'
222
229
 
223
230
  let(:options) do
224
231
  { compressors: ['zlib', 'snoopy'] }
@@ -235,7 +242,8 @@ describe Mongo::Client do
235
242
  end
236
243
  end
237
244
 
238
- context 'when the compressor is not supported by the server', unless: collation_enabled? do
245
+ context 'when the compressor is not supported by the server' do
246
+ max_server_version '3.4'
239
247
 
240
248
  let(:options) do
241
249
  { compressors: ['zlib'] }
@@ -248,7 +256,8 @@ describe Mongo::Client do
248
256
  end
249
257
  end
250
258
 
251
- context 'when compressors are not provided', unless: compression_enabled? do
259
+ context 'when compressors are not provided' do
260
+ require_no_compression
252
261
 
253
262
  let(:client) do
254
263
  authorized_client
@@ -268,7 +277,9 @@ describe Mongo::Client do
268
277
  end
269
278
  end
270
279
 
271
- context 'when a zlib_compression_level option is provided', if: testing_compression? do
280
+ context 'when a zlib_compression_level option is provided' do
281
+ require_compression
282
+ min_server_fcv '3.6'
272
283
 
273
284
  let(:client) do
274
285
  new_local_client_nmio(SpecConfig.instance.addresses, SpecConfig.instance.test_options.merge(zlib_compression_level: 1))
@@ -502,7 +502,8 @@ describe Mongo::Client do
502
502
  )
503
503
  end
504
504
 
505
- context 'when filter criteria is present', if: sessions_enabled? do
505
+ context 'when filter criteria is present' do
506
+ min_server_fcv '3.6'
506
507
 
507
508
  let(:result) do
508
509
  root_authorized_client.database_names(filter)
@@ -528,7 +529,8 @@ describe Mongo::Client do
528
529
  end).to include('admin')
529
530
  end
530
531
 
531
- context 'when filter criteria is present', if: sessions_enabled? do
532
+ context 'when filter criteria is present' do
533
+ min_server_fcv '3.6'
532
534
 
533
535
  let(:result) do
534
536
  root_authorized_client.list_databases(filter)
@@ -592,7 +594,8 @@ describe Mongo::Client do
592
594
  expect(result.first.options[:read]).to eq(BSON::Document.new(options)[:read])
593
595
  end
594
596
 
595
- context 'when filter criteria is present', if: sessions_enabled? do
597
+ context 'when filter criteria is present' do
598
+ min_server_fcv '3.6'
596
599
 
597
600
  let(:result) do
598
601
  client.list_mongo_databases(filter)
@@ -663,7 +666,7 @@ describe Mongo::Client do
663
666
  end
664
667
 
665
668
  context 'when sessions are supported' do
666
- min_server_version '3.6'
669
+ min_server_fcv '3.6'
667
670
  require_topology :replica_set, :sharded
668
671
 
669
672
  it 'creates a session' do
@@ -756,7 +759,7 @@ describe Mongo::Client do
756
759
  end
757
760
 
758
761
  context 'when two clients have the same cluster' do
759
- min_server_version '3.6'
762
+ min_server_fcv '3.6'
760
763
  require_topology :replica_set, :sharded
761
764
 
762
765
  let(:client) do
@@ -773,7 +776,7 @@ describe Mongo::Client do
773
776
  end
774
777
 
775
778
  context 'when two clients have different clusters' do
776
- min_server_version '3.6'
779
+ min_server_fcv '3.6'
777
780
  require_topology :replica_set, :sharded
778
781
 
779
782
  let(:client) do
@@ -791,7 +794,8 @@ describe Mongo::Client do
791
794
  end
792
795
  end
793
796
 
794
- context 'when sessions are not supported', unless: sessions_enabled? do
797
+ context 'when sessions are not supported' do
798
+ max_server_version '3.4'
795
799
 
796
800
  it 'raises an exception' do
797
801
  expect {
@@ -589,7 +589,7 @@ describe Mongo::Cluster do
589
589
  end
590
590
 
591
591
  context 'in server 3.6+' do
592
- min_server_version '3.6'
592
+ min_server_fcv '3.6'
593
593
 
594
594
  context 'in single topology' do
595
595
  require_topology :single
@@ -639,4 +639,33 @@ describe Mongo::Cluster do
639
639
  end
640
640
  end
641
641
  end
642
+
643
+ describe '#summary' do
644
+ context 'cluster has unknown servers' do
645
+ it 'includes unknown servers' do
646
+ cluster.servers_list.each do |server|
647
+ expect(server).to be_unknown
648
+ end
649
+
650
+ expect(cluster.summary).to match(/Server address=localhost/)
651
+ end
652
+ end
653
+
654
+ context 'cluster has known servers' do
655
+ let(:client) { ClientRegistry.instance.global_client('authorized') }
656
+ let(:cluster) { client.cluster }
657
+
658
+ before do
659
+ wait_for_all_servers(cluster)
660
+ end
661
+
662
+ it 'includes known servers' do
663
+ cluster.servers_list.each do |server|
664
+ expect(server).not_to be_unknown
665
+ end
666
+
667
+ expect(cluster.summary).to match(/Server address=localhost/)
668
+ end
669
+ end
670
+ end
642
671
  end
@@ -145,7 +145,7 @@ describe Mongo::Collection::View::Aggregation do
145
145
  end
146
146
 
147
147
  context 'when the initial response has no results but an active cursor' do
148
- min_server_version '3.2'
148
+ min_server_fcv '3.2'
149
149
 
150
150
  let(:documents) do
151
151
  [
@@ -177,14 +177,16 @@ describe Mongo::Collection::View::Aggregation do
177
177
  Mongo::Collection::View.new(collection, selector, view_options)
178
178
  end
179
179
 
180
- context 'when the server supports write concern on the aggregate command', if: collation_enabled? do
180
+ context 'when the server supports write concern on the aggregate command' do
181
+ min_server_fcv '3.4'
181
182
 
182
183
  it 'does not apply the write concern' do
183
184
  expect(aggregation.to_a.size).to eq(2)
184
185
  end
185
186
  end
186
187
 
187
- context 'when the server does not support write concern on the aggregation command', unless: collation_enabled? do
188
+ context 'when the server does not support write concern on the aggregation command' do
189
+ max_server_version '3.2'
188
190
 
189
191
  it 'does not apply the write concern' do
190
192
  expect(aggregation.to_a.size).to eq(2)
@@ -223,7 +225,7 @@ describe Mongo::Collection::View::Aggregation do
223
225
  end
224
226
 
225
227
  context 'session id' do
226
- min_server_version '3.6'
228
+ min_server_fcv '3.6'
227
229
  require_topology :replica_set, :sharded
228
230
 
229
231
  let(:options) do
@@ -266,7 +268,8 @@ describe Mongo::Collection::View::Aggregation do
266
268
  aggregation.explain['$cursor']['queryPlanner']['collation']['locale']
267
269
  end
268
270
 
269
- context 'when the server selected supports collations', if: collation_enabled? do
271
+ context 'when the server selected supports collations' do
272
+ min_server_fcv '3.4'
270
273
 
271
274
  context 'when the collation key is a String' do
272
275
 
@@ -291,7 +294,8 @@ describe Mongo::Collection::View::Aggregation do
291
294
  end
292
295
  end
293
296
 
294
- context 'when the server selected does not support collations', unless: collation_enabled? do
297
+ context 'when the server selected does not support collations' do
298
+ max_server_version '3.2'
295
299
 
296
300
  let(:options) do
297
301
  { collation: { locale: 'en_US', strength: 2 } }
@@ -507,14 +511,16 @@ describe Mongo::Collection::View::Aggregation do
507
511
  aggregation.collect { |doc| doc['name']}
508
512
  end
509
513
 
510
- context 'when the server selected supports collations', if: collation_enabled? do
514
+ context 'when the server selected supports collations' do
515
+ min_server_fcv '3.4'
511
516
 
512
517
  it 'applies the collation' do
513
518
  expect(result).to eq(['bang', 'bang'])
514
519
  end
515
520
  end
516
521
 
517
- context 'when the server selected does not support collations', unless: collation_enabled? do
522
+ context 'when the server selected does not support collations' do
523
+ max_server_version '3.2'
518
524
 
519
525
  it 'raises an exception' do
520
526
  expect {
@@ -610,7 +616,8 @@ describe Mongo::Collection::View::Aggregation do
610
616
  Mongo::Collection::View.new(collection, selector, view_options)
611
617
  end
612
618
 
613
- context 'when the server supports write concern on the aggregate command', if: collation_enabled? do
619
+ context 'when the server supports write concern on the aggregate command' do
620
+ min_server_fcv '3.4'
614
621
 
615
622
  it 'uses the write concern' do
616
623
  expect {
@@ -619,7 +626,8 @@ describe Mongo::Collection::View::Aggregation do
619
626
  end
620
627
  end
621
628
 
622
- context 'when the server does not support write concern on the aggregation command', unless: collation_enabled? do
629
+ context 'when the server does not support write concern on the aggregation command' do
630
+ max_server_version '3.2'
623
631
 
624
632
  let(:documents) do
625
633
  [
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Collection::View::ChangeStream, if: test_change_streams? do
3
+ describe Mongo::Collection::View::ChangeStream do
4
+ min_server_fcv '3.6'
5
+ require_topology :replica_set
4
6
 
5
7
  let(:pipeline) do
6
8
  []
@@ -214,7 +216,7 @@ describe Mongo::Collection::View::ChangeStream, if: test_change_streams? do
214
216
  }.to raise_exception(Mongo::Error::OperationFailure)
215
217
  end
216
218
 
217
- context 'when the operation fails', if: test_change_streams? do
219
+ context 'when the operation fails' do
218
220
 
219
221
  let!(:before_last_use) do
220
222
  session.instance_variable_get(:@server_session).last_use
@@ -270,7 +272,8 @@ describe Mongo::Collection::View::ChangeStream, if: test_change_streams? do
270
272
  end
271
273
  end
272
274
 
273
- context 'when provided a session', if: sessions_enabled? && test_change_streams? do
275
+ context 'when provided a session' do
276
+ min_server_fcv '3.6'
274
277
 
275
278
  let(:options) do
276
279
  { session: session }
@@ -383,6 +386,7 @@ describe Mongo::Collection::View::ChangeStream, if: test_change_streams? do
383
386
  end
384
387
 
385
388
  context 'when some documents have been retrieved and the stream is closed before sending getMore' do
389
+ fails_on_jruby
386
390
 
387
391
  before do
388
392
  change_stream
@@ -437,11 +441,26 @@ describe Mongo::Collection::View::ChangeStream, if: test_change_streams? do
437
441
  authorized_collection.insert_one(a: 1)
438
442
  end
439
443
 
440
- it 'raises an exception and closes the cursor' do
441
- expect(cursor).to receive(:kill_cursors).and_call_original
442
- expect {
443
- change_stream.to_enum.next
444
- }.to raise_exception(Mongo::Error::MissingResumeToken)
444
+ context 'pre-4.1 server' do
445
+ max_server_version '4.0'
446
+
447
+ it 'driver raises an exception and closes the cursor' do
448
+ expect(cursor).to receive(:kill_cursors).and_call_original
449
+ expect {
450
+ change_stream.to_enum.next
451
+ }.to raise_exception(Mongo::Error::MissingResumeToken)
452
+ end
453
+ end
454
+
455
+ context '4.1+ server' do
456
+ min_server_fcv '4.2'
457
+
458
+ it 'server errors, driver closes the cursor' do
459
+ expect(cursor).to receive(:kill_cursors).and_call_original
460
+ expect {
461
+ change_stream.to_enum.next
462
+ }.to raise_exception(Mongo::Error::OperationFailure, /Encountered an event whose _id field, which contains the resume token, was modified by the pipeline. Modifying the _id field of an event makes it impossible to resume the stream from that point. Only transformations that retain the unmodified _id field are allowed./)
463
+ end
445
464
  end
446
465
  end
447
466
 
@@ -574,6 +593,7 @@ describe Mongo::Collection::View::ChangeStream, if: test_change_streams? do
574
593
  end
575
594
 
576
595
  context 'when a server error is encountered during a getMore' do
596
+ fails_on_jruby
577
597
 
578
598
  context 'when the error is a resumable error' do
579
599
 
@@ -223,7 +223,7 @@ describe Mongo::Collection::View::MapReduce do
223
223
  end
224
224
 
225
225
  context 'when the output collection is iterated' do
226
- min_server_version '3.6'
226
+ min_server_fcv '3.6'
227
227
  require_topology :replica_set, :sharded
228
228
 
229
229
  let(:options) do
@@ -257,19 +257,22 @@ describe Mongo::Collection::View::MapReduce do
257
257
  end
258
258
  end
259
259
 
260
- context 'when another db is specified', if: (sessions_enabled? && !sharded? && !auth_enabled?) do
260
+ context 'when another db is specified' do
261
+ min_server_fcv '3.6'
262
+ require_topology :single, :replica_set
263
+ require_no_auth
261
264
 
262
265
  let(:new_map_reduce) do
263
266
  map_reduce.out(db: 'another-db', replace: 'output_collection')
264
267
  end
265
268
 
266
- it 'iterates over the documents in the result', if: (sessions_enabled? && !sharded? && !auth_enabled?) do
269
+ it 'iterates over the documents in the result' do
267
270
  new_map_reduce.each do |document|
268
271
  expect(document[:value]).to_not be_nil
269
272
  end
270
273
  end
271
274
 
272
- it 'fetches the results from the collection', if: (sessions_enabled? && !sharded? && !auth_enabled?) do
275
+ it 'fetches the results from the collection' do
273
276
  expect(new_map_reduce.count).to eq(2)
274
277
  end
275
278
  end
@@ -291,7 +294,10 @@ describe Mongo::Collection::View::MapReduce do
291
294
  expect(new_map_reduce.count).to eq(2)
292
295
  end
293
296
 
294
- context 'when another db is specified', if: (!auth_enabled? && !sharded? && list_command_enabled?) do
297
+ context 'when another db is specified' do
298
+ min_server_fcv '3.0'
299
+ require_topology :single, :replica_set
300
+ require_no_auth
295
301
 
296
302
  let(:new_map_reduce) do
297
303
  map_reduce.out(db: 'another-db', merge: 'output_collection')
@@ -325,7 +331,10 @@ describe Mongo::Collection::View::MapReduce do
325
331
  expect(new_map_reduce.count).to eq(2)
326
332
  end
327
333
 
328
- context 'when another db is specified', if: (!auth_enabled? && list_command_enabled? && !sharded?) do
334
+ context 'when another db is specified' do
335
+ min_server_fcv '3.0'
336
+ require_topology :single, :replica_set
337
+ require_no_auth
329
338
 
330
339
  let(:new_map_reduce) do
331
340
  map_reduce.out(db: 'another-db', reduce: 'output_collection')
@@ -585,7 +594,9 @@ describe Mongo::Collection::View::MapReduce do
585
594
 
586
595
  shared_examples_for 'map reduce that writes accepting write concern' do
587
596
 
588
- context 'when the server supports write concern on the mapReduce command', if: (collation_enabled? && standalone?) do
597
+ context 'when the server supports write concern on the mapReduce command' do
598
+ min_server_fcv '3.4'
599
+ require_topology :single
589
600
 
590
601
  it 'uses the write concern' do
591
602
  expect {
@@ -594,7 +605,8 @@ describe Mongo::Collection::View::MapReduce do
594
605
  end
595
606
  end
596
607
 
597
- context 'when the server does not support write concern on the mapReduce command', unless: collation_enabled? do
608
+ context 'when the server does not support write concern on the mapReduce command' do
609
+ max_server_version '3.2'
598
610
 
599
611
  it 'does not apply the write concern' do
600
612
  expect(map_reduce.to_a.size).to eq(2)
@@ -747,7 +759,8 @@ describe Mongo::Collection::View::MapReduce do
747
759
  { name: 'BANG' }
748
760
  end
749
761
 
750
- context 'when the server selected supports collations', if: collation_enabled? do
762
+ context 'when the server selected supports collations' do
763
+ min_server_fcv '3.4'
751
764
 
752
765
  context 'when the collation key is a String' do
753
766
 
@@ -772,7 +785,8 @@ describe Mongo::Collection::View::MapReduce do
772
785
  end
773
786
  end
774
787
 
775
- context 'when the server selected does not support collations', unless: collation_enabled? do
788
+ context 'when the server selected does not support collations' do
789
+ max_server_version '3.2'
776
790
 
777
791
  context 'when the map reduce has collation specified in its options' do
778
792
 
@@ -21,7 +21,7 @@ describe Mongo::Collection::View::Readable do
21
21
  shared_examples_for 'a read concern aware operation' do
22
22
 
23
23
  context 'when a read concern is provided' do
24
- min_server_version '3.2'
24
+ min_server_fcv '3.2'
25
25
 
26
26
  let(:new_view) do
27
27
  Mongo::Collection::View.new(new_collection, selector, options)
@@ -321,13 +321,18 @@ describe Mongo::Collection::View::Readable do
321
321
  end
322
322
  end
323
323
 
324
- it 'takes a read preference option', unless: sharded? do
325
- # Secondary may be delayed, since this tests wants 10 documents
326
- # it must query the primary
327
- expect(view.count(read: { mode: :primary })).to eq(10)
324
+ context 'not sharded' do
325
+ require_topology :single, :replica_set
326
+
327
+ it 'takes a read preference option' do
328
+ # Secondary may be delayed, since this tests wants 10 documents
329
+ # it must query the primary
330
+ expect(view.count(read: { mode: :primary })).to eq(10)
331
+ end
328
332
  end
329
333
 
330
- context 'when a read preference is set on the view', unless: sharded? do
334
+ context 'when a read preference is set on the view' do
335
+ require_topology :single, :replica_set
331
336
 
332
337
  let(:client) do
333
338
  # Set a timeout otherwise, the test will hang for 30 seconds.
@@ -411,7 +416,8 @@ describe Mongo::Collection::View::Readable do
411
416
  end
412
417
  end
413
418
 
414
- context 'when no read preference argument is provided', unless: sharded? do
419
+ context 'when no read preference argument is provided' do
420
+ require_topology :single, :replica_set
415
421
 
416
422
  before do
417
423
  allow(view.collection.client.cluster).to receive(:single?).and_return(false)
@@ -428,7 +434,8 @@ describe Mongo::Collection::View::Readable do
428
434
  end
429
435
  end
430
436
 
431
- context 'when the collection does not have a read preference set', unless: sharded? do
437
+ context 'when the collection does not have a read preference set' do
438
+ require_topology :single, :replica_set
432
439
 
433
440
  after do
434
441
  client.close
@@ -506,14 +513,16 @@ describe Mongo::Collection::View::Readable do
506
513
  { collation: { locale: 'en_US', strength: 2 } }
507
514
  end
508
515
 
509
- context 'when the server selected supports collations', if: collation_enabled? do
516
+ context 'when the server selected supports collations' do
517
+ min_server_fcv '3.4'
510
518
 
511
519
  it 'applies the collation to the count' do
512
520
  expect(result).to eq(1)
513
521
  end
514
522
  end
515
523
 
516
- context 'when the server selected does not support collations', unless: collation_enabled? do
524
+ context 'when the server selected does not support collations' do
525
+ max_server_version '3.2'
517
526
 
518
527
  it 'raises an exception' do
519
528
  expect {
@@ -554,14 +563,16 @@ describe Mongo::Collection::View::Readable do
554
563
  { collation: { locale: 'en_US', strength: 2 } }
555
564
  end
556
565
 
557
- context 'when the server selected supports collations', if: collation_enabled? do
566
+ context 'when the server selected supports collations' do
567
+ min_server_fcv '3.4'
558
568
 
559
569
  it 'applies the collation to the count' do
560
570
  expect(result).to eq(1)
561
571
  end
562
572
  end
563
573
 
564
- context 'when the server selected does not support collations', unless: collation_enabled? do
574
+ context 'when the server selected does not support collations' do
575
+ max_server_version '3.2'
565
576
 
566
577
  it 'raises an exception' do
567
578
  expect {
@@ -699,7 +710,8 @@ describe Mongo::Collection::View::Readable do
699
710
  end
700
711
  end
701
712
 
702
- context 'when a read preference is set on the view', unless: sharded? do
713
+ context 'when a read preference is set on the view' do
714
+ require_topology :single, :replica_set
703
715
 
704
716
  let(:client) do
705
717
  # Set a timeout otherwise, the test will hang for 30 seconds.
@@ -776,7 +788,8 @@ describe Mongo::Collection::View::Readable do
776
788
  end
777
789
  end
778
790
 
779
- context 'when no read preference argument is provided', unless: sharded? do
791
+ context 'when no read preference argument is provided' do
792
+ require_topology :single, :replica_set
780
793
 
781
794
  before do
782
795
  allow(view.collection.client.cluster).to receive(:single?).and_return(false)
@@ -793,7 +806,8 @@ describe Mongo::Collection::View::Readable do
793
806
  end
794
807
  end
795
808
 
796
- context 'when the collection does not have a read preference set', unless: sharded? do
809
+ context 'when the collection does not have a read preference set' do
810
+ require_topology :single, :replica_set
797
811
 
798
812
  let(:documents) do
799
813
  (1..3).map{ |i| { field: "test#{i}" }}
@@ -891,14 +905,16 @@ describe Mongo::Collection::View::Readable do
891
905
  { collation: { locale: 'en_US', strength: 2 } }
892
906
  end
893
907
 
894
- context 'when the server selected supports collations', if: collation_enabled? do
908
+ context 'when the server selected supports collations' do
909
+ min_server_fcv '3.4'
895
910
 
896
911
  it 'applies the collation to the distinct' do
897
912
  expect(result).to eq(['bang'])
898
913
  end
899
914
  end
900
915
 
901
- context 'when the server selected does not support collations', unless: collation_enabled? do
916
+ context 'when the server selected does not support collations' do
917
+ max_server_version '3.2'
902
918
 
903
919
  it 'raises an exception' do
904
920
  expect {
@@ -936,14 +952,16 @@ describe Mongo::Collection::View::Readable do
936
952
  { collation: { locale: 'en_US', strength: 2 } }
937
953
  end
938
954
 
939
- context 'when the server selected supports collations', if: collation_enabled? do
955
+ context 'when the server selected supports collations' do
956
+ min_server_fcv '3.4'
940
957
 
941
958
  it 'applies the collation to the distinct' do
942
959
  expect(result).to eq(['bang'])
943
960
  end
944
961
  end
945
962
 
946
- context 'when the server selected does not support collations', unless: collation_enabled? do
963
+ context 'when the server selected does not support collations' do
964
+ max_server_version '3.2'
947
965
 
948
966
  it 'raises an exception' do
949
967
  expect {