mongo 2.18.0 → 2.18.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 (118) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongo/bulk_write.rb +7 -5
  4. data/lib/mongo/client.rb +1 -1
  5. data/lib/mongo/collection/view/writable.rb +0 -2
  6. data/lib/mongo/collection.rb +150 -45
  7. data/lib/mongo/crypt/auto_encrypter.rb +30 -9
  8. data/lib/mongo/crypt/binding.rb +93 -1
  9. data/lib/mongo/crypt/explicit_encrypter.rb +5 -1
  10. data/lib/mongo/crypt/handle.rb +33 -0
  11. data/lib/mongo/crypt/kms.rb +0 -1
  12. data/lib/mongo/cursor.rb +6 -1
  13. data/lib/mongo/error/invalid_read_option.rb +1 -1
  14. data/lib/mongo/operation/aggregate.rb +1 -2
  15. data/lib/mongo/operation/collections_info.rb +3 -15
  16. data/lib/mongo/operation/command.rb +1 -2
  17. data/lib/mongo/operation/count.rb +1 -2
  18. data/lib/mongo/operation/create.rb +1 -2
  19. data/lib/mongo/operation/create_index.rb +1 -2
  20. data/lib/mongo/operation/create_user.rb +1 -2
  21. data/lib/mongo/operation/delete.rb +0 -1
  22. data/lib/mongo/operation/distinct.rb +1 -2
  23. data/lib/mongo/operation/drop.rb +1 -2
  24. data/lib/mongo/operation/drop_database.rb +1 -2
  25. data/lib/mongo/operation/drop_index.rb +1 -2
  26. data/lib/mongo/operation/explain.rb +1 -3
  27. data/lib/mongo/operation/find/builder.rb +0 -1
  28. data/lib/mongo/operation/find.rb +1 -3
  29. data/lib/mongo/operation/get_more.rb +1 -3
  30. data/lib/mongo/operation/indexes.rb +1 -17
  31. data/lib/mongo/operation/insert.rb +0 -1
  32. data/lib/mongo/operation/kill_cursors.rb +1 -2
  33. data/lib/mongo/operation/list_collections.rb +1 -2
  34. data/lib/mongo/operation/map_reduce.rb +1 -2
  35. data/lib/mongo/operation/parallel_scan.rb +1 -2
  36. data/lib/mongo/operation/remove_user.rb +1 -2
  37. data/lib/mongo/operation/shared/{polymorphic_operation.rb → op_msg_executable.rb} +11 -6
  38. data/lib/mongo/operation/shared/sessions_supported.rb +7 -3
  39. data/lib/mongo/operation/update.rb +0 -1
  40. data/lib/mongo/operation/update_user.rb +1 -2
  41. data/lib/mongo/operation/users_info.rb +1 -2
  42. data/lib/mongo/operation/write_command.rb +1 -2
  43. data/lib/mongo/operation.rb +1 -3
  44. data/lib/mongo/protocol.rb +0 -3
  45. data/lib/mongo/query_cache.rb +20 -20
  46. data/lib/mongo/session.rb +1 -1
  47. data/lib/mongo/version.rb +1 -1
  48. data/spec/README.md +5 -1
  49. data/spec/integration/bulk_write_spec.rb +16 -0
  50. data/spec/integration/command_spec.rb +1 -23
  51. data/spec/integration/ocsp_verifier_spec.rb +2 -0
  52. data/spec/mongo/client_construction_spec.rb +4 -4
  53. data/spec/mongo/collection_crud_spec.rb +56 -0
  54. data/spec/mongo/collection_spec.rb +11 -1
  55. data/spec/mongo/crypt/auto_encrypter_spec.rb +41 -6
  56. data/spec/mongo/crypt/binding/version_spec.rb +8 -0
  57. data/spec/mongo/crypt/handle_spec.rb +102 -0
  58. data/spec/mongo/crypt/kms_spec.rb +12 -9
  59. data/spec/mongo/cursor_spec.rb +50 -0
  60. data/spec/shared/lib/mrss/event_subscriber.rb +15 -5
  61. data/spec/spec_tests/data/change_streams_unified/change-streams-resume-errorLabels.yml +3 -0
  62. data/spec/spec_tests/data/client_side_encryption/unified/rewrapManyDataKey.yml +3 -3
  63. data/spec/spec_tests/data/sdam_integration/hello-command-error.yml +6 -14
  64. data/spec/spec_tests/data/sdam_integration/hello-network-error.yml +4 -14
  65. data/spec/spec_tests/data/sdam_integration/hello-timeout.yml +8 -14
  66. data/spec/spec_tests/data/transactions_unified/do-not-retry-read-in-transaction.yml +64 -0
  67. data/spec/spec_tests/data/transactions_unified/retryable-abort-handshake.yml +118 -0
  68. data/spec/spec_tests/data/transactions_unified/retryable-commit-handshake.yml +118 -0
  69. data/spec/support/certificates/retrieve-atlas-cert +38 -0
  70. data/spec/support/spec_config.rb +4 -0
  71. data.tar.gz.sig +0 -0
  72. metadata +1133 -1178
  73. metadata.gz.sig +0 -0
  74. data/lib/mongo/operation/aggregate/command.rb +0 -55
  75. data/lib/mongo/operation/collections_info/command.rb +0 -48
  76. data/lib/mongo/operation/command/command.rb +0 -41
  77. data/lib/mongo/operation/count/command.rb +0 -47
  78. data/lib/mongo/operation/create/command.rb +0 -47
  79. data/lib/mongo/operation/create_index/command.rb +0 -61
  80. data/lib/mongo/operation/create_user/command.rb +0 -46
  81. data/lib/mongo/operation/delete/command.rb +0 -52
  82. data/lib/mongo/operation/distinct/command.rb +0 -47
  83. data/lib/mongo/operation/drop/command.rb +0 -41
  84. data/lib/mongo/operation/drop_database/command.rb +0 -41
  85. data/lib/mongo/operation/drop_index/command.rb +0 -45
  86. data/lib/mongo/operation/explain/command.rb +0 -58
  87. data/lib/mongo/operation/explain/legacy.rb +0 -52
  88. data/lib/mongo/operation/find/builder/legacy.rb +0 -123
  89. data/lib/mongo/operation/find/command.rb +0 -51
  90. data/lib/mongo/operation/find/legacy/result.rb +0 -46
  91. data/lib/mongo/operation/find/legacy.rb +0 -52
  92. data/lib/mongo/operation/get_more/command.rb +0 -43
  93. data/lib/mongo/operation/get_more/legacy.rb +0 -39
  94. data/lib/mongo/operation/indexes/command.rb +0 -42
  95. data/lib/mongo/operation/indexes/legacy.rb +0 -48
  96. data/lib/mongo/operation/insert/command.rb +0 -55
  97. data/lib/mongo/operation/kill_cursors/command.rb +0 -48
  98. data/lib/mongo/operation/list_collections/command.rb +0 -46
  99. data/lib/mongo/operation/map_reduce/command.rb +0 -51
  100. data/lib/mongo/operation/parallel_scan/command.rb +0 -57
  101. data/lib/mongo/operation/remove_user/command.rb +0 -46
  102. data/lib/mongo/operation/shared/op_msg_or_command.rb +0 -41
  103. data/lib/mongo/operation/shared/op_msg_or_find_command.rb +0 -44
  104. data/lib/mongo/operation/update/command.rb +0 -53
  105. data/lib/mongo/operation/update_user/command.rb +0 -45
  106. data/lib/mongo/operation/users_info/command.rb +0 -46
  107. data/lib/mongo/operation/write_command/command.rb +0 -51
  108. data/lib/mongo/protocol/delete.rb +0 -172
  109. data/lib/mongo/protocol/insert.rb +0 -181
  110. data/lib/mongo/protocol/update.rb +0 -214
  111. data/spec/mongo/operation/delete/command_spec.rb +0 -115
  112. data/spec/mongo/operation/find/legacy_spec.rb +0 -131
  113. data/spec/mongo/operation/get_more_spec.rb +0 -63
  114. data/spec/mongo/operation/insert/command_spec.rb +0 -118
  115. data/spec/mongo/operation/update/command_spec.rb +0 -122
  116. data/spec/mongo/protocol/delete_spec.rb +0 -185
  117. data/spec/mongo/protocol/insert_spec.rb +0 -179
  118. data/spec/mongo/protocol/update_spec.rb +0 -204
@@ -50,6 +50,15 @@ module Mongo
50
50
  # and schemaMap, an error will be raised.
51
51
  # @option options [ Boolean | nil ] :bypass_query_analysis When true
52
52
  # disables automatic analysis of outgoing commands.
53
+ # @option options [ String | nil ] :crypt_shared_lib_path Path that should
54
+ # be the used to load the crypt shared library. Providing this option
55
+ # overrides default crypt shared library load paths for libmongocrypt.
56
+ # @option options [ Boolean | nil ] :crypt_shared_lib_required Whether
57
+ # crypt_shared library is required. If 'true', an error will be raised
58
+ # if a crypt_shared library cannot be loaded by libmongocrypt.
59
+ # @option options [ Boolean | nil ] :explicit_encryption_only Whether this
60
+ # handle is going to be used only for explicit encryption. If true,
61
+ # libmongocrypt is instructed not to load crypt shared library.
53
62
  # @option options [ Logger ] :logger A Logger object to which libmongocrypt logs
54
63
  # will be sent
55
64
  def initialize(kms_providers, kms_tls_options, options={})
@@ -70,13 +79,29 @@ module Mongo
70
79
  @bypass_query_analysis = options[:bypass_query_analysis]
71
80
  set_bypass_query_analysis if @bypass_query_analysis
72
81
 
82
+ @crypt_shared_lib_path = options[:crypt_shared_lib_path]
83
+ @explicit_encryption_only = options[:explicit_encryption_only]
84
+ if @crypt_shared_lib_path
85
+ Binding.setopt_set_crypt_shared_lib_path_override(self, @crypt_shared_lib_path)
86
+ elsif !@bypass_query_analysis && !@explicit_encryption_only
87
+ Binding.setopt_append_crypt_shared_lib_search_path(self, "$SYSTEM")
88
+ end
89
+
73
90
  @logger = options[:logger]
74
91
  set_logger_callback if @logger
75
92
 
76
93
  set_crypto_hooks
77
94
 
78
95
  Binding.setopt_kms_providers(self, kms_providers.to_document)
96
+
79
97
  initialize_mongocrypt
98
+
99
+ @crypt_shared_lib_required = !!options[:crypt_shared_lib_required]
100
+ if @crypt_shared_lib_required && crypt_shared_lib_version == 0
101
+ raise Mongo::Error::CryptError.new(
102
+ "Crypt shared library is required, but cannot be loaded according to libmongocrypt"
103
+ )
104
+ end
80
105
  end
81
106
 
82
107
  # Return the reference to the underlying @mongocrypt object
@@ -96,6 +121,14 @@ module Mongo
96
121
  @kms_tls_options.fetch(provider, {})
97
122
  end
98
123
 
124
+ def crypt_shared_lib_version
125
+ Binding.crypt_shared_lib_version(self)
126
+ end
127
+
128
+ def crypt_shared_lib_available?
129
+ crypt_shared_lib_version != 0
130
+ end
131
+
99
132
  private
100
133
 
101
134
  # Set the schema map option on the underlying mongocrypt_t object
@@ -89,7 +89,6 @@ module Mongo
89
89
  %i(
90
90
  ssl_verify_certificate
91
91
  ssl_verify_hostname
92
- ssl_verify_ocsp_endpoint
93
92
  ).each do |opt|
94
93
  if provider_opts[opt] == false
95
94
  raise ArgumentError.new(
data/lib/mongo/cursor.rb CHANGED
@@ -251,7 +251,12 @@ module Mongo
251
251
  #
252
252
  # @since 2.2.0
253
253
  def batch_size
254
- @view.batch_size && @view.batch_size > 0 ? @view.batch_size : limit
254
+ value = @view.batch_size && @view.batch_size > 0 ? @view.batch_size : limit
255
+ if value == 0
256
+ nil
257
+ else
258
+ value
259
+ end
255
260
  end
256
261
 
257
262
  # Is the cursor closed?
@@ -31,7 +31,7 @@ module Mongo
31
31
  #
32
32
  # @since 2.6.0
33
33
  def initialize(read_option, msg)
34
- super("Invalid read option: #{read_option}: #{msg}")
34
+ super("Invalid read preference value: #{read_option.inspect}: #{msg}")
35
35
  end
36
36
  end
37
37
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/aggregate/command'
19
18
  require 'mongo/operation/aggregate/op_msg'
20
19
  require 'mongo/operation/aggregate/result'
21
20
 
@@ -33,7 +32,7 @@ module Mongo
33
32
  # @since 2.0.0
34
33
  class Aggregate
35
34
  include Specifiable
36
- include OpMsgOrCommand
35
+ include OpMsgExecutable
37
36
  end
38
37
  end
39
38
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/collections_info/command'
19
18
  require 'mongo/operation/collections_info/result'
20
19
 
21
20
  module Mongo
@@ -28,23 +27,12 @@ module Mongo
28
27
  # @since 2.0.0
29
28
  class CollectionsInfo
30
29
  include Specifiable
31
- include PolymorphicOperation
32
- include PolymorphicLookup
30
+ include OpMsgExecutable
33
31
 
34
32
  private
35
33
 
36
- def final_operation(connection)
37
- op_class = if connection.features.list_collections_enabled?
38
- if connection.features.op_msg_enabled?
39
- ListCollections::OpMsg
40
- else
41
- ListCollections::Command
42
- end
43
- else
44
- CollectionsInfo::Command
45
- end
46
-
47
- op_class.new(spec)
34
+ def final_operation
35
+ ListCollections::OpMsg.new(spec)
48
36
  end
49
37
  end
50
38
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/command/command'
19
18
  require 'mongo/operation/command/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.0.0
29
28
  class Command
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/count/command'
19
18
  require 'mongo/operation/count/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.0.0
29
28
  class Count
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/create/command'
19
18
  require 'mongo/operation/create/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.0.0
29
28
  class Create
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/create_index/command'
19
18
  require 'mongo/operation/create_index/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.0.0
29
28
  class CreateIndex
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/create_user/command'
19
18
  require 'mongo/operation/create_user/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.0.0
29
28
  class CreateUser
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/delete/command'
19
18
  require 'mongo/operation/delete/op_msg'
20
19
  require 'mongo/operation/delete/result'
21
20
  require 'mongo/operation/delete/bulk_result'
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/distinct/command'
19
18
  require 'mongo/operation/distinct/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.5.0
29
28
  class Distinct
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/drop/command'
19
18
  require 'mongo/operation/drop/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.4.0
29
28
  class Drop
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/drop_database/command'
19
18
  require 'mongo/operation/drop_database/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.4.0
29
28
  class DropDatabase
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/drop_index/command'
19
18
  require 'mongo/operation/drop_index/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.0.0
29
28
  class DropIndex
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -17,8 +17,6 @@
17
17
 
18
18
  require 'mongo/operation/explain/result'
19
19
  require 'mongo/operation/explain/op_msg'
20
- require 'mongo/operation/explain/command'
21
- require 'mongo/operation/explain/legacy'
22
20
 
23
21
  module Mongo
24
22
  module Operation
@@ -30,7 +28,7 @@ module Mongo
30
28
  # @since 2.5.0
31
29
  class Explain
32
30
  include Specifiable
33
- include OpMsgOrFindCommand
31
+ include OpMsgExecutable
34
32
  end
35
33
  end
36
34
  end
@@ -17,5 +17,4 @@
17
17
 
18
18
  require 'mongo/operation/find/builder/command'
19
19
  require 'mongo/operation/find/builder/flags'
20
- require 'mongo/operation/find/builder/legacy'
21
20
  require 'mongo/operation/find/builder/modifiers'
@@ -15,9 +15,7 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/find/command'
19
18
  require 'mongo/operation/find/op_msg'
20
- require 'mongo/operation/find/legacy'
21
19
  require 'mongo/operation/find/result'
22
20
  require 'mongo/operation/find/builder'
23
21
 
@@ -31,7 +29,7 @@ module Mongo
31
29
  # @since 2.0.0
32
30
  class Find
33
31
  include Specifiable
34
- include OpMsgOrFindCommand
32
+ include OpMsgExecutable
35
33
  end
36
34
  end
37
35
  end
@@ -16,9 +16,7 @@
16
16
  # limitations under the License.
17
17
 
18
18
  require 'mongo/operation/get_more/command_builder'
19
- require 'mongo/operation/get_more/command'
20
19
  require 'mongo/operation/get_more/op_msg'
21
- require 'mongo/operation/get_more/legacy'
22
20
  require 'mongo/operation/get_more/result'
23
21
 
24
22
  module Mongo
@@ -31,7 +29,7 @@ module Mongo
31
29
  # @since 2.5.0
32
30
  class GetMore
33
31
  include Specifiable
34
- include OpMsgOrFindCommand
32
+ include OpMsgExecutable
35
33
  end
36
34
  end
37
35
  end
@@ -15,9 +15,7 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/indexes/command'
19
18
  require 'mongo/operation/indexes/op_msg'
20
- require 'mongo/operation/indexes/legacy'
21
19
  require 'mongo/operation/indexes/result'
22
20
 
23
21
  module Mongo
@@ -30,21 +28,7 @@ module Mongo
30
28
  # @since 2.0.0
31
29
  class Indexes
32
30
  include Specifiable
33
- include PolymorphicOperation
34
- include PolymorphicLookup
35
-
36
- private
37
-
38
- def final_operation(connection)
39
- cls = if connection.features.op_msg_enabled?
40
- polymorphic_class(self.class.name, :OpMsg)
41
- elsif connection.features.list_indexes_enabled?
42
- polymorphic_class(self.class.name, :Command)
43
- else
44
- polymorphic_class(self.class.name, :Legacy)
45
- end
46
- cls.new(spec)
47
- end
31
+ include OpMsgExecutable
48
32
  end
49
33
  end
50
34
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/insert/command'
19
18
  require 'mongo/operation/insert/op_msg'
20
19
  require 'mongo/operation/insert/result'
21
20
  require 'mongo/operation/insert/bulk_result'
@@ -16,7 +16,6 @@
16
16
  # limitations under the License.
17
17
 
18
18
  require 'mongo/operation/kill_cursors/command_builder'
19
- require 'mongo/operation/kill_cursors/command'
20
19
  require 'mongo/operation/kill_cursors/op_msg'
21
20
 
22
21
  module Mongo
@@ -29,7 +28,7 @@ module Mongo
29
28
  # @since 2.0.0
30
29
  class KillCursors
31
30
  include Specifiable
32
- include OpMsgOrFindCommand
31
+ include OpMsgExecutable
33
32
  end
34
33
  end
35
34
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/list_collections/command'
19
18
  require 'mongo/operation/list_collections/op_msg'
20
19
  require 'mongo/operation/list_collections/result'
21
20
 
@@ -29,7 +28,7 @@ module Mongo
29
28
  # @since 2.0.0
30
29
  class ListCollections
31
30
  include Specifiable
32
- include OpMsgOrCommand
31
+ include OpMsgExecutable
33
32
  end
34
33
  end
35
34
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/map_reduce/command'
19
18
  require 'mongo/operation/map_reduce/op_msg'
20
19
  require 'mongo/operation/map_reduce/result'
21
20
 
@@ -29,7 +28,7 @@ module Mongo
29
28
  # @since 2.5.0
30
29
  class MapReduce
31
30
  include Specifiable
32
- include OpMsgOrCommand
31
+ include OpMsgExecutable
33
32
  end
34
33
  end
35
34
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/parallel_scan/command'
19
18
  require 'mongo/operation/parallel_scan/op_msg'
20
19
  require 'mongo/operation/parallel_scan/result'
21
20
 
@@ -29,7 +28,7 @@ module Mongo
29
28
  # @since 2.0.0
30
29
  class ParallelScan
31
30
  include Specifiable
32
- include OpMsgOrCommand
31
+ include OpMsgExecutable
33
32
  end
34
33
  end
35
34
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/remove_user/command'
19
18
  require 'mongo/operation/remove_user/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.0.0
29
28
  class RemoveUser
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  # encoding: utf-8
3
3
 
4
- # Copyright (C) 2021 MongoDB Inc.
4
+ # Copyright (C) 2018-2020 MongoDB Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -18,11 +18,11 @@
18
18
  module Mongo
19
19
  module Operation
20
20
 
21
- # Shared behavior of implementing an operation differently based on
22
- # the server that will be executing the operation.
21
+ # Shared behavior of executing the operation as an OpMsg.
23
22
  #
24
23
  # @api private
25
- module PolymorphicOperation
24
+ module OpMsgExecutable
25
+ include PolymorphicLookup
26
26
 
27
27
  # Execute the operation.
28
28
  #
@@ -46,8 +46,13 @@ module Mongo
46
46
  #
47
47
  # @return [ Mongo::Operation::Result ] The operation result.
48
48
  def execute_with_connection(connection, context:, options: {})
49
- operation = final_operation(connection)
50
- operation.execute(connection, context: context, options: options)
49
+ final_operation.execute(connection, context: context, options: options)
50
+ end
51
+
52
+ private
53
+
54
+ def final_operation
55
+ polymorphic_class(self.class.name, :OpMsg).new(spec)
51
56
  end
52
57
  end
53
58
  end
@@ -257,10 +257,14 @@ module Mongo
257
257
  super.tap do |message|
258
258
  if session = context.session
259
259
  # Serialize the message to detect client-side problems,
260
- # such as invalid BSON keys. The message will be serialized again
260
+ # such as invalid BSON keys or too large messages.
261
+ # The message will be serialized again
261
262
  # later prior to being sent to the connection.
262
- message.serialize(BSON::ByteBuffer.new)
263
-
263
+ buf = BSON::ByteBuffer.new
264
+ message.serialize(buf)
265
+ if buf.length > connection.max_message_size
266
+ raise Error::MaxMessageSize.new(connection.max_message_size)
267
+ end
264
268
  session.update_state!
265
269
  end
266
270
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/update/command'
19
18
  require 'mongo/operation/update/op_msg'
20
19
  require 'mongo/operation/update/result'
21
20
  require 'mongo/operation/update/bulk_result'
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/update_user/command'
19
18
  require 'mongo/operation/update_user/op_msg'
20
19
 
21
20
  module Mongo
@@ -28,7 +27,7 @@ module Mongo
28
27
  # @since 2.0.0
29
28
  class UpdateUser
30
29
  include Specifiable
31
- include OpMsgOrCommand
30
+ include OpMsgExecutable
32
31
  end
33
32
  end
34
33
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/users_info/command'
19
18
  require 'mongo/operation/users_info/op_msg'
20
19
  require 'mongo/operation/users_info/result'
21
20
 
@@ -29,7 +28,7 @@ module Mongo
29
28
  # @since 2.0.0
30
29
  class UsersInfo
31
30
  include Specifiable
32
- include OpMsgOrCommand
31
+ include OpMsgExecutable
33
32
  end
34
33
  end
35
34
  end
@@ -15,7 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require 'mongo/operation/write_command/command'
19
18
  require 'mongo/operation/write_command/op_msg'
20
19
 
21
20
  module Mongo
@@ -26,7 +25,7 @@ module Mongo
26
25
  # @api private
27
26
  class WriteCommand
28
27
  include Specifiable
29
- include OpMsgOrCommand
28
+ include OpMsgExecutable
30
29
  end
31
30
  end
32
31
  end
@@ -9,7 +9,6 @@ require 'mongo/operation/shared/executable'
9
9
  require 'mongo/operation/shared/executable_no_validate'
10
10
  require 'mongo/operation/shared/executable_transaction_label'
11
11
  require 'mongo/operation/shared/polymorphic_lookup'
12
- require 'mongo/operation/shared/polymorphic_operation'
13
12
  require 'mongo/operation/shared/polymorphic_result'
14
13
  require 'mongo/operation/shared/read_preference_supported'
15
14
  require 'mongo/operation/shared/bypass_document_validation'
@@ -22,8 +21,7 @@ require 'mongo/operation/shared/idable'
22
21
  require 'mongo/operation/shared/specifiable'
23
22
  require 'mongo/operation/shared/validatable'
24
23
  require 'mongo/operation/shared/object_id_generator'
25
- require 'mongo/operation/shared/op_msg_or_command'
26
- require 'mongo/operation/shared/op_msg_or_find_command'
24
+ require 'mongo/operation/shared/op_msg_executable'
27
25
 
28
26
  require 'mongo/operation/op_msg_base'
29
27
  require 'mongo/operation/command'
@@ -10,12 +10,9 @@ require 'mongo/protocol/caching_hash'
10
10
 
11
11
  # Client Requests
12
12
  require 'mongo/protocol/compressed'
13
- require 'mongo/protocol/delete'
14
13
  require 'mongo/protocol/get_more'
15
- require 'mongo/protocol/insert'
16
14
  require 'mongo/protocol/kill_cursors'
17
15
  require 'mongo/protocol/query'
18
- require 'mongo/protocol/update'
19
16
  require 'mongo/protocol/msg'
20
17
 
21
18
  # Server Responses