mongo 2.13.1 → 2.14.0.rc1

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 (161) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -4
  4. data/lib/mongo.rb +9 -0
  5. data/lib/mongo/address/ipv4.rb +1 -1
  6. data/lib/mongo/address/ipv6.rb +1 -1
  7. data/lib/mongo/bulk_write.rb +17 -0
  8. data/lib/mongo/caching_cursor.rb +74 -0
  9. data/lib/mongo/client.rb +47 -8
  10. data/lib/mongo/cluster.rb +3 -3
  11. data/lib/mongo/cluster/topology/single.rb +1 -1
  12. data/lib/mongo/collection.rb +26 -0
  13. data/lib/mongo/collection/view.rb +24 -20
  14. data/lib/mongo/collection/view/aggregation.rb +25 -4
  15. data/lib/mongo/collection/view/builder/find_command.rb +38 -18
  16. data/lib/mongo/collection/view/explainable.rb +27 -8
  17. data/lib/mongo/collection/view/iterable.rb +72 -12
  18. data/lib/mongo/collection/view/readable.rb +12 -2
  19. data/lib/mongo/collection/view/writable.rb +15 -1
  20. data/lib/mongo/crypt/encryption_io.rb +6 -6
  21. data/lib/mongo/cursor.rb +1 -0
  22. data/lib/mongo/database.rb +6 -0
  23. data/lib/mongo/error.rb +2 -0
  24. data/lib/mongo/error/invalid_read_concern.rb +28 -0
  25. data/lib/mongo/error/server_certificate_revoked.rb +22 -0
  26. data/lib/mongo/error/unsupported_option.rb +14 -12
  27. data/lib/mongo/lint.rb +2 -1
  28. data/lib/mongo/logger.rb +3 -3
  29. data/lib/mongo/operation.rb +2 -0
  30. data/lib/mongo/operation/aggregate/result.rb +9 -8
  31. data/lib/mongo/operation/collections_info/result.rb +2 -0
  32. data/lib/mongo/operation/delete/bulk_result.rb +2 -0
  33. data/lib/mongo/operation/delete/result.rb +3 -0
  34. data/lib/mongo/operation/explain/command.rb +4 -0
  35. data/lib/mongo/operation/explain/legacy.rb +4 -0
  36. data/lib/mongo/operation/explain/op_msg.rb +6 -0
  37. data/lib/mongo/operation/explain/result.rb +3 -0
  38. data/lib/mongo/operation/find/legacy/result.rb +2 -0
  39. data/lib/mongo/operation/find/result.rb +3 -0
  40. data/lib/mongo/operation/get_more/result.rb +3 -0
  41. data/lib/mongo/operation/indexes/result.rb +5 -0
  42. data/lib/mongo/operation/insert/bulk_result.rb +5 -0
  43. data/lib/mongo/operation/insert/result.rb +5 -0
  44. data/lib/mongo/operation/list_collections/result.rb +5 -0
  45. data/lib/mongo/operation/map_reduce/result.rb +10 -0
  46. data/lib/mongo/operation/parallel_scan/result.rb +4 -0
  47. data/lib/mongo/operation/result.rb +35 -6
  48. data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
  49. data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
  50. data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
  51. data/lib/mongo/operation/shared/executable.rb +1 -0
  52. data/lib/mongo/operation/shared/idable.rb +2 -1
  53. data/lib/mongo/operation/shared/limited.rb +1 -0
  54. data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
  55. data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
  56. data/lib/mongo/operation/shared/sessions_supported.rb +1 -0
  57. data/lib/mongo/operation/shared/specifiable.rb +1 -0
  58. data/lib/mongo/operation/shared/write.rb +1 -0
  59. data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
  60. data/lib/mongo/operation/update/legacy/result.rb +7 -0
  61. data/lib/mongo/operation/update/result.rb +8 -0
  62. data/lib/mongo/operation/users_info/result.rb +3 -0
  63. data/lib/mongo/query_cache.rb +242 -0
  64. data/lib/mongo/retryable.rb +8 -1
  65. data/lib/mongo/server.rb +5 -1
  66. data/lib/mongo/server/connection_common.rb +2 -2
  67. data/lib/mongo/server/connection_pool.rb +3 -0
  68. data/lib/mongo/server/monitor.rb +1 -1
  69. data/lib/mongo/server/monitor/connection.rb +3 -3
  70. data/lib/mongo/server/pending_connection.rb +2 -2
  71. data/lib/mongo/server/push_monitor.rb +1 -1
  72. data/lib/mongo/server_selector/base.rb +5 -1
  73. data/lib/mongo/session.rb +3 -0
  74. data/lib/mongo/socket.rb +6 -4
  75. data/lib/mongo/socket/ocsp_cache.rb +97 -0
  76. data/lib/mongo/socket/ocsp_verifier.rb +368 -0
  77. data/lib/mongo/socket/ssl.rb +45 -24
  78. data/lib/mongo/srv/monitor.rb +7 -13
  79. data/lib/mongo/srv/resolver.rb +14 -10
  80. data/lib/mongo/timeout.rb +2 -0
  81. data/lib/mongo/uri.rb +21 -390
  82. data/lib/mongo/uri/options_mapper.rb +582 -0
  83. data/lib/mongo/uri/srv_protocol.rb +3 -2
  84. data/lib/mongo/utils.rb +12 -1
  85. data/lib/mongo/version.rb +1 -1
  86. data/spec/NOTES.aws-auth.md +12 -7
  87. data/spec/README.md +56 -1
  88. data/spec/integration/bulk_write_spec.rb +48 -0
  89. data/spec/integration/client_authentication_options_spec.rb +55 -28
  90. data/spec/integration/connection_pool_populator_spec.rb +3 -1
  91. data/spec/integration/cursor_reaping_spec.rb +53 -17
  92. data/spec/integration/ocsp_connectivity_spec.rb +26 -0
  93. data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
  94. data/spec/integration/ocsp_verifier_spec.rb +334 -0
  95. data/spec/integration/query_cache_spec.rb +1045 -0
  96. data/spec/integration/query_cache_transactions_spec.rb +179 -0
  97. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
  98. data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -0
  99. data/spec/integration/sdam_error_handling_spec.rb +68 -0
  100. data/spec/integration/server_selection_spec.rb +36 -0
  101. data/spec/integration/srv_monitoring_spec.rb +38 -3
  102. data/spec/integration/srv_spec.rb +56 -0
  103. data/spec/lite_spec_helper.rb +3 -1
  104. data/spec/mongo/address_spec.rb +1 -1
  105. data/spec/mongo/caching_cursor_spec.rb +70 -0
  106. data/spec/mongo/client_construction_spec.rb +54 -1
  107. data/spec/mongo/client_spec.rb +40 -0
  108. data/spec/mongo/cluster/topology/single_spec.rb +14 -5
  109. data/spec/mongo/cluster_spec.rb +3 -0
  110. data/spec/mongo/collection/view/explainable_spec.rb +87 -4
  111. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
  112. data/spec/mongo/collection_spec.rb +60 -0
  113. data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
  114. data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
  115. data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
  116. data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
  117. data/spec/mongo/database_spec.rb +44 -0
  118. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  119. data/spec/mongo/logger_spec.rb +13 -11
  120. data/spec/mongo/query_cache_spec.rb +279 -0
  121. data/spec/mongo/server/connection_pool_spec.rb +7 -3
  122. data/spec/mongo/server/connection_spec.rb +14 -7
  123. data/spec/mongo/socket/ssl_spec.rb +1 -1
  124. data/spec/mongo/socket_spec.rb +1 -1
  125. data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
  126. data/spec/mongo/uri_option_parsing_spec.rb +11 -11
  127. data/spec/mongo/uri_spec.rb +68 -41
  128. data/spec/mongo/utils_spec.rb +39 -0
  129. data/spec/runners/auth.rb +3 -0
  130. data/spec/runners/connection_string.rb +35 -124
  131. data/spec/spec_tests/cmap_spec.rb +7 -3
  132. data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -1
  133. data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
  134. data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
  135. data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
  136. data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
  137. data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
  138. data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
  139. data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
  140. data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
  141. data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
  142. data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
  143. data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
  144. data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
  145. data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
  146. data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
  147. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
  148. data/spec/spec_tests/uri_options_spec.rb +31 -33
  149. data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
  150. data/spec/support/certificates/atlas-ocsp.crt +41 -0
  151. data/spec/support/client_registry_macros.rb +11 -2
  152. data/spec/support/common_shortcuts.rb +45 -0
  153. data/spec/support/constraints.rb +23 -0
  154. data/spec/support/lite_constraints.rb +24 -0
  155. data/spec/support/matchers.rb +16 -0
  156. data/spec/support/ocsp +1 -0
  157. data/spec/support/session_registry.rb +52 -0
  158. data/spec/support/spec_config.rb +22 -0
  159. data/spec/support/utils.rb +19 -1
  160. metadata +38 -3
  161. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd4f9d74906d6f99fd038c0a3b4cfe0ee5cc3a7a4b327debf9c57649112b2cbb
4
- data.tar.gz: 052b3f3af1749d9f26d8e3655359650653b4bf71e9198a3d2116afde6d576eb3
3
+ metadata.gz: 493d0cb29d48d80c7fe4c87691500c078b6667bd214dcc021e0074938229be83
4
+ data.tar.gz: 44507b68e42abadad6987f50c3b3ae1b8ae70f046812607755ffbe292013ccc4
5
5
  SHA512:
6
- metadata.gz: c016d60512a77572e58ae6553dc9e61ecf6574abc724785858c43987aa84d7b79199589a9be7da702d6385d48f70f65fe135caa36176f9cf6fb638c3e156afc4
7
- data.tar.gz: a5c0dbab135a661a3cec5b0eab3300308693474d4c6662b0a18dd33b303f86753390eb0880232794a09ba511824f5d863f7bf428a8af1ca7b7b511458c078049
6
+ metadata.gz: ea39c71265e24349b018a8e5f5699b556d1ed43107135da46790ad8496c4bcd8a3917ca6fd0c7b405c5e6cff968d6e18cedf35ac33fe660f19f2869f663cdf64
7
+ data.tar.gz: 30ca549b30bec1889f622f7002658c918b6686e417bd9a636777bbc7f321d06094278b5a7ff4b04a9395f61bf90e28f99f26ff9ec404b0e3687dbc1b4a77ec1f
Binary file
data.tar.gz.sig CHANGED
@@ -1,4 +1 @@
1
- ���_�.�Y��В�,8Q�c|���Sa8�Iy� @T�+�8�%R���\!���|����~��jm����o������\v:�*�*^4�����ϒH�3l/�q%r(�0\�􆕵/�ң�).����ٞz��) ���H�G��'Τaa��~'%,y;��qf
2
- ����
3
- �P\�?ރ.r\P{�a2+�`J"
4
- =]�{�<�;7�Mp+��v�)\<r���/h]0`���T`< -��hP]��kW�8ŀu~����+��|�s3_�
1
+ lb~�{������z�x�%����~��n��3G���k�j*R0
@@ -51,6 +51,7 @@ require 'mongo/protocol'
51
51
  require 'mongo/background_thread'
52
52
  require 'mongo/cluster'
53
53
  require 'mongo/cursor'
54
+ require 'mongo/caching_cursor'
54
55
  require 'mongo/collection'
55
56
  require 'mongo/database'
56
57
  require 'mongo/crypt'
@@ -60,6 +61,7 @@ require 'mongo/dbref'
60
61
  require 'mongo/grid'
61
62
  require 'mongo/index'
62
63
  require 'mongo/lint'
64
+ require 'mongo/query_cache'
63
65
  require 'mongo/server'
64
66
  require 'mongo/server_selector'
65
67
  require 'mongo/session'
@@ -70,3 +72,10 @@ require 'mongo/uri'
70
72
  require 'mongo/version'
71
73
  require 'mongo/write_concern'
72
74
  require 'mongo/utils'
75
+
76
+ module Mongo
77
+ # Clears the driver's OCSP response cache.
78
+ module_function def clear_ocsp_cache
79
+ Socket::OcspCache.clear
80
+ end
81
+ end
@@ -81,7 +81,7 @@ module Mongo
81
81
  # @param [ Hash ] options The options.
82
82
  #
83
83
  # @option options [ Float ] :connect_timeout Connect timeout.
84
- # @option options [ true | false ] :ssl Whether to use SSL.
84
+ # @option options [ true | false ] :ssl Whether to use TLS.
85
85
  # @option options [ String ] :ssl_ca_cert
86
86
  # Same as the corresponding Client/Socket::SSL option.
87
87
  # @option options [ Array<OpenSSL::X509::Certificate> ] :ssl_ca_cert_object
@@ -95,7 +95,7 @@ module Mongo
95
95
  # @param [ Hash ] options The options.
96
96
  #
97
97
  # @option options [ Float ] :connect_timeout Connect timeout.
98
- # @option options [ true | false ] :ssl Whether to use SSL.
98
+ # @option options [ true | false ] :ssl Whether to use TLS.
99
99
  # @option options [ String ] :ssl_ca_cert
100
100
  # Same as the corresponding Client/Socket::SSL option.
101
101
  # @option options [ Array<OpenSSL::X509::Certificate> ] :ssl_ca_cert_object
@@ -195,6 +195,13 @@ module Mongo
195
195
  end
196
196
  end
197
197
  end
198
+ # With OP_MSG (3.6+ servers), the size of each section in the message
199
+ # is independently capped at 16m and each bulk operation becomes
200
+ # its own section. The size of the entire bulk write is limited to 48m.
201
+ # With OP_QUERY (pre-3.6 servers), the entire bulk write is sent as a
202
+ # single document and is thus subject to the 16m document size limit.
203
+ # This means the splits differ between pre-3.6 and 3.6+ servers, with
204
+ # 3.6+ servers being able to split less.
198
205
  rescue Error::MaxBSONSize, Error::MaxMessageSize => e
199
206
  raise e if values.size <= 1
200
207
  unpin_maybe(session) do
@@ -214,27 +221,37 @@ module Mongo
214
221
  end
215
222
 
216
223
  def delete_one(documents, connection, operation_id, session, txn_num)
224
+ QueryCache.clear_namespace(collection.namespace)
225
+
217
226
  spec = base_spec(operation_id, session).merge(:deletes => documents, :txn_num => txn_num)
218
227
  Operation::Delete.new(spec).bulk_execute(connection, client: client)
219
228
  end
220
229
 
221
230
  def delete_many(documents, connection, operation_id, session, txn_num)
231
+ QueryCache.clear_namespace(collection.namespace)
232
+
222
233
  spec = base_spec(operation_id, session).merge(:deletes => documents)
223
234
  Operation::Delete.new(spec).bulk_execute(connection, client: client)
224
235
  end
225
236
 
226
237
  def insert_one(documents, connection, operation_id, session, txn_num)
238
+ QueryCache.clear_namespace(collection.namespace)
239
+
227
240
  spec = base_spec(operation_id, session).merge(:documents => documents, :txn_num => txn_num)
228
241
  Operation::Insert.new(spec).bulk_execute(connection, client: client)
229
242
  end
230
243
 
231
244
  def update_one(documents, connection, operation_id, session, txn_num)
245
+ QueryCache.clear_namespace(collection.namespace)
246
+
232
247
  spec = base_spec(operation_id, session).merge(:updates => documents, :txn_num => txn_num)
233
248
  Operation::Update.new(spec).bulk_execute(connection, client: client)
234
249
  end
235
250
  alias :replace_one :update_one
236
251
 
237
252
  def update_many(documents, connection, operation_id, session, txn_num)
253
+ QueryCache.clear_namespace(collection.namespace)
254
+
238
255
  spec = base_spec(operation_id, session).merge(:updates => documents)
239
256
  Operation::Update.new(spec).bulk_execute(connection, client: client)
240
257
  end
@@ -0,0 +1,74 @@
1
+ # Copyright (C) 2020 MongoDB Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Mongo
16
+
17
+ # A Cursor that attempts to load documents from memory first before hitting
18
+ # the database if the same query has already been executed.
19
+ #
20
+ # @api semiprivate
21
+ class CachingCursor < Cursor
22
+
23
+ # @return [ Array <BSON::Document> ] The cursor's cached documents.
24
+ # @api private
25
+ attr_reader :cached_docs
26
+
27
+ # We iterate over the cached documents if they exist already in the
28
+ # cursor otherwise proceed as normal.
29
+ #
30
+ # @example Iterate over the documents.
31
+ # cursor.each do |doc|
32
+ # # ...
33
+ # end
34
+ def each
35
+ if @cached_docs
36
+ @cached_docs.each do |doc|
37
+ yield doc
38
+ end
39
+
40
+ unless closed?
41
+ # StopIteration raised by try_next ends this loop.
42
+ loop do
43
+ document = try_next
44
+ yield document if document
45
+ end
46
+ end
47
+ else
48
+ super
49
+ end
50
+ end
51
+
52
+ # Get a human-readable string representation of +Cursor+.
53
+ #
54
+ # @example Inspect the cursor.
55
+ # cursor.inspect
56
+ #
57
+ # @return [ String ] A string representation of a +Cursor+ instance.
58
+ def inspect
59
+ "#<Mongo::CachingCursor:0x#{object_id} @view=#{@view.inspect}>"
60
+ end
61
+
62
+ # Acquires the next document for cursor iteration and then
63
+ # inserts that document in the @cached_docs array.
64
+ #
65
+ # @api private
66
+ def try_next
67
+ @cached_docs ||= []
68
+ document = super
69
+ @cached_docs << document if document
70
+
71
+ document
72
+ end
73
+ end
74
+ end
@@ -101,6 +101,7 @@ module Mongo
101
101
  :ssl_verify,
102
102
  :ssl_verify_certificate,
103
103
  :ssl_verify_hostname,
104
+ :ssl_verify_ocsp_endpoint,
104
105
  :truncate_logs,
105
106
  :user,
106
107
  :wait_queue_timeout,
@@ -315,7 +316,7 @@ module Mongo
315
316
  # for selecting a server for an operation.
316
317
  # @option options [ Float ] :socket_timeout The timeout, in seconds, to
317
318
  # execute operations on a socket.
318
- # @option options [ true, false ] :ssl Whether to use SSL.
319
+ # @option options [ true, false ] :ssl Whether to use TLS.
319
320
  # @option options [ String ] :ssl_ca_cert The file containing concatenated
320
321
  # certificate authority certificates used to validate certs passed from the
321
322
  # other end of the connection. Intermediate certificates should NOT be
@@ -462,6 +463,8 @@ module Mongo
462
463
  @srv_records = nil
463
464
  end
464
465
 
466
+ options = self.class.canonicalize_ruby_options(options)
467
+
465
468
  # Special handling for sdam_proc as it is only used during client
466
469
  # construction
467
470
  sdam_proc = options.delete(:sdam_proc)
@@ -478,6 +481,12 @@ module Mongo
478
481
  end
479
482
  options = merged_options
480
483
 
484
+ options.keys.each do |k|
485
+ if options[k].nil?
486
+ options.delete(k)
487
+ end
488
+ end
489
+
481
490
  @options = validate_new_options!(options)
482
491
  =begin WriteConcern object support
483
492
  if @options[:write_concern].is_a?(WriteConcern::Base)
@@ -605,15 +614,12 @@ module Mongo
605
614
 
606
615
  # Get a summary of the client state.
607
616
  #
608
- # @note This method is experimental and subject to change.
617
+ # @note The exact format and layout of the returned summary string is
618
+ # not part of the driver's public API and may be changed at any time.
609
619
  #
610
- # @example Inspect the client.
611
- # client.summary
612
- #
613
- # @return [ String ] Summary string.
620
+ # @return [ String ] The summary string.
614
621
  #
615
622
  # @since 2.7.0
616
- # @api experimental
617
623
  def summary
618
624
  "#<Client cluster=#{cluster.summary}>"
619
625
  end
@@ -769,7 +775,6 @@ module Mongo
769
775
  options[:read_concern]
770
776
  end
771
777
 
772
-
773
778
  # Get the write concern for this client. If no option was provided, then a
774
779
  # default single server acknowledgement will be used.
775
780
  #
@@ -1022,6 +1027,23 @@ module Mongo
1022
1027
  end
1023
1028
  end
1024
1029
 
1030
+ class << self
1031
+ # Lowercases auth mechanism properties, if given, in the specified
1032
+ # options, then converts the options to an instance of Options::Redacted.
1033
+ #
1034
+ # @api private
1035
+ def canonicalize_ruby_options(options)
1036
+ Options::Redacted.new(Hash[options.map do |k, v|
1037
+ if k == :auth_mech_properties || k == 'auth_mech_properties'
1038
+ if v
1039
+ v = Hash[v.map { |pk, pv| [pk.downcase, pv] }]
1040
+ end
1041
+ end
1042
+ [k, v]
1043
+ end])
1044
+ end
1045
+ end
1046
+
1025
1047
  private
1026
1048
 
1027
1049
  # Create a new encrypter object using the client's auto encryption options
@@ -1107,6 +1129,23 @@ module Mongo
1107
1129
  # but does not check for interactions between combinations of options.
1108
1130
  def validate_new_options!(opts = Options::Redacted.new)
1109
1131
  return Options::Redacted.new unless opts
1132
+ if opts[:read_concern]
1133
+ # Raise an error for non user-settable options
1134
+ if opts[:read_concern][:after_cluster_time]
1135
+ raise Mongo::Error::InvalidReadConcern.new(
1136
+ 'The after_cluster_time read_concern option cannot be specified by the user'
1137
+ )
1138
+ end
1139
+
1140
+ given_keys = opts[:read_concern].keys.map(&:to_s)
1141
+ allowed_keys = ['level']
1142
+ invalid_keys = given_keys - allowed_keys
1143
+ # Warn that options are invalid but keep it and forward to the server
1144
+ unless invalid_keys.empty?
1145
+ log_warn("Read concern has invalid keys: #{invalid_keys.join(',')}.")
1146
+ end
1147
+ end
1148
+
1110
1149
  Lint.validate_underscore_read_preference(opts[:read])
1111
1150
  Lint.validate_read_concern_option(opts[:read_concern])
1112
1151
  opts.each.inject(Options::Redacted.new) do |_options, (k, v)|
@@ -950,9 +950,9 @@ module Mongo
950
950
  # Start SRV monitor
951
951
  @srv_monitor_lock.synchronize do
952
952
  unless @srv_monitor
953
- monitor_options = options.merge(
954
- timeout: options[:connect_timeout] || Server::CONNECT_TIMEOUT)
955
- @srv_monitor = _srv_monitor = Srv::Monitor.new(self, monitor_options)
953
+ monitor_options = Utils.shallow_symbolize_keys(options.merge(
954
+ timeout: options[:connect_timeout] || Server::CONNECT_TIMEOUT))
955
+ @srv_monitor = _srv_monitor = Srv::Monitor.new(self, **monitor_options)
956
956
  finalizer = lambda do
957
957
  _srv_monitor.stop!
958
958
  end
@@ -133,7 +133,7 @@ module Mongo
133
133
 
134
134
  def validate_options(options, cluster)
135
135
  if cluster.servers_list.length > 1
136
- raise ArgumentError, 'Cannot instantiate a single topology with more than one server in the cluster'
136
+ raise ArgumentError, "Cannot instantiate a single topology with more than one server in the cluster: #{cluster.servers_list.map(&:address).map(&:seed).join(', ')}"
137
137
  end
138
138
 
139
139
  super(options, cluster)
@@ -223,6 +223,7 @@ module Mongo
223
223
  # @param [ Hash ] opts The options for the create operation.
224
224
  #
225
225
  # @option options [ Session ] :session The session to use for the operation.
226
+ # @option opts [ Hash ] :write_concern The write concern options.
226
227
  #
227
228
  # @return [ Result ] The result of the command.
228
229
  #
@@ -239,6 +240,11 @@ module Mongo
239
240
  operation.delete(:write)
240
241
  operation.delete(:write_concern)
241
242
  client.send(:with_session, opts) do |session|
243
+ write_concern = if opts[:write_concern]
244
+ WriteConcern.get(opts[:write_concern])
245
+ else
246
+ self.write_concern
247
+ end
242
248
  server = next_primary(nil, session)
243
249
  if (options[:collation] || options[Operation::COLLATION]) && !server.with_connection { |connection| connection.features }.collation_enabled?
244
250
  raise Error::UnsupportedCollation
@@ -264,12 +270,19 @@ module Mongo
264
270
  # @param [ Hash ] opts The options for the drop operation.
265
271
  #
266
272
  # @option options [ Session ] :session The session to use for the operation.
273
+ # @option opts [ Hash ] :write_concern The write concern options.
267
274
  #
268
275
  # @return [ Result ] The result of the command.
269
276
  #
270
277
  # @since 2.0.0
271
278
  def drop(opts = {})
272
279
  client.send(:with_session, opts) do |session|
280
+ temp_write_concern = write_concern
281
+ write_concern = if opts[:write_concern]
282
+ WriteConcern.get(opts[:write_concern])
283
+ else
284
+ temp_write_concern
285
+ end
273
286
  Operation::Drop.new({
274
287
  selector: { :drop => name },
275
288
  db_name: database.name,
@@ -543,6 +556,8 @@ module Mongo
543
556
  #
544
557
  # @since 2.0.0
545
558
  def insert_one(document, opts = {})
559
+ QueryCache.clear_namespace(namespace)
560
+
546
561
  client.send(:with_session, opts) do |session|
547
562
  write_concern = if opts[:write_concern]
548
563
  WriteConcern.get(opts[:write_concern])
@@ -579,6 +594,8 @@ module Mongo
579
594
  #
580
595
  # @since 2.0.0
581
596
  def insert_many(documents, options = {})
597
+ QueryCache.clear_namespace(namespace)
598
+
582
599
  inserts = documents.map{ |doc| { :insert_one => doc }}
583
600
  bulk_write(inserts, options)
584
601
  end
@@ -861,5 +878,14 @@ module Mongo
861
878
  def namespace
862
879
  "#{database.name}.#{name}"
863
880
  end
881
+
882
+ # Whether the collection is a system collection.
883
+ #
884
+ # @return [ Boolean ] Whether the system is a system collection.
885
+ #
886
+ # @api private
887
+ def system_collection?
888
+ name.start_with?('system.')
889
+ end
864
890
  end
865
891
  end
@@ -120,27 +120,31 @@ module Mongo
120
120
  # server can write temporary data to disk while executing the find
121
121
  # operation. This option is only available on MongoDB server versions
122
122
  # 4.4 and newer.
123
- # @option options :comment [ String ] Associate a comment with the query.
124
- # @option options :batch_size [ Integer ] The number of docs to return in
125
- # each response from MongoDB.
126
- # @option options :projection [ Hash ] The fields to include or exclude in
127
- # returned docs.
128
- # @option options :hint [ Hash ] Override default index selection and force
129
- # MongoDB to use a specific index for the query.
130
- # @option options :limit [ Integer ] Max number of docs to return.
131
- # @option options :max_scan [ Integer ] Constrain the query to only scan the
132
- # specified number of docs. Use to prevent queries from running too long.
133
- # Deprecated as of MongoDB server version 4.0.
134
- # @option options :read [ Symbol ] The read preference to use for the query.
135
- # If none is provided, the collection's default read preference is used.
136
- # @option options :show_disk_loc [ true, false ] Return disk location info as
137
- # a field in each doc.
138
- # @option options :skip [ Integer ] The number of documents to skip.
139
- # @option options :snapshot [ true, false ] Prevents returning a doc more than
140
- # once. Deprecated as of MongoDB server version 4.0.
141
- # @option options :sort [ Hash ] The key and direction pairs used to sort the
142
- # results.
123
+ # @option options [ Integer ] :batch_size The number of documents to
124
+ # return in each response from MongoDB.
143
125
  # @option options [ Hash ] :collation The collation to use.
126
+ # @option options [ String ] :comment Associate a comment with the query.
127
+ # @option options [ Hash ] :explain Execute an explain with the provided
128
+ # explain options (known options are :verbose and :verbosity) rather
129
+ # than a find.
130
+ # @option options [ Hash ] :hint Override the default index selection and
131
+ # force MongoDB to use a specific index for the query.
132
+ # @option options [ Integer ] :limit Max number of documents to return.
133
+ # @option options [ Integer ] :max_scan Constrain the query to only scan
134
+ # the specified number of documents. Use to prevent queries from
135
+ # running for too long. Deprecated as of MongoDB server version 4.0.
136
+ # @option options [ Hash ] :projection The fields to include or exclude
137
+ # in the returned documents.
138
+ # @option options [ Hash ] :read The read preference to use for the
139
+ # query. If none is provided, the collection's default read preference
140
+ # is used.
141
+ # @option options [ true | false ] :show_disk_loc Return disk location
142
+ # info as a field in each doc.
143
+ # @option options [ Integer ] :skip The number of documents to skip.
144
+ # @option options [ true | false ] :snapshot Prevents returning a
145
+ # document more than once. Deprecated as of MongoDB server version 4.0.
146
+ # @option options [ Hash ] :sort The key and direction pairs used to sort
147
+ # the results.
144
148
  #
145
149
  # @since 2.0.0
146
150
  def initialize(collection, filter = {}, options = {})