mongo 2.18.1 → 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 (94) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongo/bulk_write.rb +6 -4
  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/kms.rb +0 -1
  8. data/lib/mongo/error/invalid_read_option.rb +1 -1
  9. data/lib/mongo/operation/aggregate.rb +1 -2
  10. data/lib/mongo/operation/collections_info.rb +3 -15
  11. data/lib/mongo/operation/command.rb +1 -2
  12. data/lib/mongo/operation/count.rb +1 -2
  13. data/lib/mongo/operation/create.rb +1 -2
  14. data/lib/mongo/operation/create_index.rb +1 -2
  15. data/lib/mongo/operation/create_user.rb +1 -2
  16. data/lib/mongo/operation/delete.rb +0 -1
  17. data/lib/mongo/operation/distinct.rb +1 -2
  18. data/lib/mongo/operation/drop.rb +1 -2
  19. data/lib/mongo/operation/drop_database.rb +1 -2
  20. data/lib/mongo/operation/drop_index.rb +1 -2
  21. data/lib/mongo/operation/explain.rb +1 -3
  22. data/lib/mongo/operation/find/builder.rb +0 -1
  23. data/lib/mongo/operation/find.rb +1 -3
  24. data/lib/mongo/operation/get_more.rb +1 -3
  25. data/lib/mongo/operation/indexes.rb +1 -17
  26. data/lib/mongo/operation/insert.rb +0 -1
  27. data/lib/mongo/operation/kill_cursors.rb +1 -2
  28. data/lib/mongo/operation/list_collections.rb +1 -2
  29. data/lib/mongo/operation/map_reduce.rb +1 -2
  30. data/lib/mongo/operation/parallel_scan.rb +1 -2
  31. data/lib/mongo/operation/remove_user.rb +1 -2
  32. data/lib/mongo/operation/shared/{polymorphic_operation.rb → op_msg_executable.rb} +11 -6
  33. data/lib/mongo/operation/update.rb +0 -1
  34. data/lib/mongo/operation/update_user.rb +1 -2
  35. data/lib/mongo/operation/users_info.rb +1 -2
  36. data/lib/mongo/operation/write_command.rb +1 -2
  37. data/lib/mongo/operation.rb +1 -3
  38. data/lib/mongo/protocol.rb +0 -3
  39. data/lib/mongo/query_cache.rb +20 -20
  40. data/lib/mongo/session.rb +1 -1
  41. data/lib/mongo/version.rb +1 -1
  42. data/spec/integration/command_spec.rb +1 -23
  43. data/spec/mongo/client_construction_spec.rb +4 -4
  44. data/spec/mongo/collection_crud_spec.rb +56 -0
  45. data/spec/mongo/collection_spec.rb +11 -1
  46. data/spec/mongo/crypt/kms_spec.rb +12 -9
  47. data.tar.gz.sig +0 -0
  48. metadata +1133 -1186
  49. metadata.gz.sig +0 -0
  50. data/lib/mongo/operation/aggregate/command.rb +0 -55
  51. data/lib/mongo/operation/collections_info/command.rb +0 -48
  52. data/lib/mongo/operation/command/command.rb +0 -41
  53. data/lib/mongo/operation/count/command.rb +0 -47
  54. data/lib/mongo/operation/create/command.rb +0 -47
  55. data/lib/mongo/operation/create_index/command.rb +0 -61
  56. data/lib/mongo/operation/create_user/command.rb +0 -46
  57. data/lib/mongo/operation/delete/command.rb +0 -52
  58. data/lib/mongo/operation/distinct/command.rb +0 -47
  59. data/lib/mongo/operation/drop/command.rb +0 -41
  60. data/lib/mongo/operation/drop_database/command.rb +0 -41
  61. data/lib/mongo/operation/drop_index/command.rb +0 -45
  62. data/lib/mongo/operation/explain/command.rb +0 -58
  63. data/lib/mongo/operation/explain/legacy.rb +0 -52
  64. data/lib/mongo/operation/find/builder/legacy.rb +0 -123
  65. data/lib/mongo/operation/find/command.rb +0 -51
  66. data/lib/mongo/operation/find/legacy/result.rb +0 -46
  67. data/lib/mongo/operation/find/legacy.rb +0 -52
  68. data/lib/mongo/operation/get_more/command.rb +0 -43
  69. data/lib/mongo/operation/get_more/legacy.rb +0 -39
  70. data/lib/mongo/operation/indexes/command.rb +0 -42
  71. data/lib/mongo/operation/indexes/legacy.rb +0 -48
  72. data/lib/mongo/operation/insert/command.rb +0 -55
  73. data/lib/mongo/operation/kill_cursors/command.rb +0 -48
  74. data/lib/mongo/operation/list_collections/command.rb +0 -46
  75. data/lib/mongo/operation/map_reduce/command.rb +0 -51
  76. data/lib/mongo/operation/parallel_scan/command.rb +0 -57
  77. data/lib/mongo/operation/remove_user/command.rb +0 -46
  78. data/lib/mongo/operation/shared/op_msg_or_command.rb +0 -41
  79. data/lib/mongo/operation/shared/op_msg_or_find_command.rb +0 -44
  80. data/lib/mongo/operation/update/command.rb +0 -53
  81. data/lib/mongo/operation/update_user/command.rb +0 -45
  82. data/lib/mongo/operation/users_info/command.rb +0 -46
  83. data/lib/mongo/operation/write_command/command.rb +0 -51
  84. data/lib/mongo/protocol/delete.rb +0 -172
  85. data/lib/mongo/protocol/insert.rb +0 -181
  86. data/lib/mongo/protocol/update.rb +0 -214
  87. data/spec/mongo/operation/delete/command_spec.rb +0 -115
  88. data/spec/mongo/operation/find/legacy_spec.rb +0 -131
  89. data/spec/mongo/operation/get_more_spec.rb +0 -63
  90. data/spec/mongo/operation/insert/command_spec.rb +0 -118
  91. data/spec/mongo/operation/update/command_spec.rb +0 -122
  92. data/spec/mongo/protocol/delete_spec.rb +0 -185
  93. data/spec/mongo/protocol/insert_spec.rb +0 -179
  94. data/spec/mongo/protocol/update_spec.rb +0 -204
@@ -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
@@ -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
@@ -114,24 +114,24 @@ module Mongo
114
114
  #
115
115
  # @param [ Mongo::CachingCursor ] cursor The CachingCursor instance to store.
116
116
  #
117
- # @option opts [ String | nil ] namespace The namespace of the query,
117
+ # @option opts [ String | nil ] :namespace The namespace of the query,
118
118
  # in the format "database_name.collection_name".
119
- # @option opts [ Array, Hash ] selector The selector passed to the query.
119
+ # @option opts [ Array, Hash ] :selector The selector passed to the query.
120
120
  # For most queries, this will be a Hash, but for aggregations, this
121
121
  # will be an Array representing the aggregation pipeline. May not be nil.
122
- # @option opts [ Integer | nil ] skip The skip value of the query.
123
- # @option opts [ Hash | nil ] sort The order of the query results
122
+ # @option opts [ Integer | nil ] :skip The skip value of the query.
123
+ # @option opts [ Hash | nil ] :sort The order of the query results
124
124
  # (e.g. { name: -1 }).
125
- # @option opts [ Integer | nil ] limit The limit value of the query.
126
- # @option opts [ Hash | nil ] projection The projection of the query
125
+ # @option opts [ Integer | nil ] :limit The limit value of the query.
126
+ # @option opts [ Hash | nil ] :projection The projection of the query
127
127
  # results (e.g. { name: 1 }).
128
- # @option opts [ Hash | nil ] collation The collation of the query
128
+ # @option opts [ Hash | nil ] :collation The collation of the query
129
129
  # (e.g. { "locale" => "fr_CA" }).
130
- # @option opts [ Hash | nil ] read_concern The read concern of the query
130
+ # @option opts [ Hash | nil ] :read_concern The read concern of the query
131
131
  # (e.g. { level: :majority }).
132
- # @option opts [ Hash | nil ] read_preference The read preference of
132
+ # @option opts [ Hash | nil ] :read_preference The read preference of
133
133
  # the query (e.g. { mode: :secondary }).
134
- # @option opts [ Boolean | nil ] multi_collection Whether the query
134
+ # @option opts [ Boolean | nil ] :multi_collection Whether the query
135
135
  # results could potentially come from multiple collections. When true,
136
136
  # these results will be stored under the nil namespace key and cleared
137
137
  # on every write command.
@@ -152,24 +152,24 @@ module Mongo
152
152
  # For the given query options, retrieve a cached cursor that can be used
153
153
  # to obtain the correct query results, if one exists in the cache.
154
154
  #
155
- # @option opts [ String | nil ] namespace The namespace of the query,
155
+ # @option opts [ String | nil ] :namespace The namespace of the query,
156
156
  # in the format "database_name.collection_name".
157
- # @option opts [ Array, Hash ] selector The selector passed to the query.
157
+ # @option opts [ Array, Hash ] :selector The selector passed to the query.
158
158
  # For most queries, this will be a Hash, but for aggregations, this
159
159
  # will be an Array representing the aggregation pipeline. May not be nil.
160
- # @option opts [ Integer | nil ] skip The skip value of the query.
161
- # @option opts [ Hash | nil ] sort The order of the query results
160
+ # @option opts [ Integer | nil ] :skip The skip value of the query.
161
+ # @option opts [ Hash | nil ] :sort The order of the query results
162
162
  # (e.g. { name: -1 }).
163
- # @option opts [ Integer | nil ] limit The limit value of the query.
164
- # @option opts [ Hash | nil ] projection The projection of the query
163
+ # @option opts [ Integer | nil ] :limit The limit value of the query.
164
+ # @option opts [ Hash | nil ] :projection The projection of the query
165
165
  # results (e.g. { name: 1 }).
166
- # @option opts [ Hash | nil ] collation The collation of the query
166
+ # @option opts [ Hash | nil ] :collation The collation of the query
167
167
  # (e.g. { "locale" => "fr_CA" }).
168
- # @option opts [ Hash | nil ] read_concern The read concern of the query
168
+ # @option opts [ Hash | nil ] :read_concern The read concern of the query
169
169
  # (e.g. { level: :majority }).
170
- # @option opts [ Hash | nil ] read_preference The read preference of
170
+ # @option opts [ Hash | nil ] :read_preference The read preference of
171
171
  # the query (e.g. { mode: :secondary }).
172
- # @option opts [ Boolean | nil ] multi_collection Whether the query
172
+ # @option opts [ Boolean | nil ] :multi_collection Whether the query
173
173
  # results could potentially come from multiple collections. When true,
174
174
  # these results will be stored under the nil namespace key and cleared
175
175
  # on every write command.
data/lib/mongo/session.rb CHANGED
@@ -522,7 +522,7 @@ module Mongo
522
522
  #
523
523
  # @option options [ Integer ] :max_commit_time_ms The maximum amount of
524
524
  # time to allow a single commitTransaction command to run, in milliseconds.
525
- # @option options [ Hash ] read_concern The read concern options hash,
525
+ # @option options [ Hash ] :read_concern The read concern options hash,
526
526
  # with the following optional keys:
527
527
  # - *:level* -- the read preference level as a symbol; valid values
528
528
  # are *:local*, *:majority*, and *:snapshot*
data/lib/mongo/version.rb CHANGED
@@ -20,5 +20,5 @@ module Mongo
20
20
  # The current version of the driver.
21
21
  #
22
22
  # @since 2.0.0
23
- VERSION = '2.18.1'.freeze
23
+ VERSION = '2.18.2'.freeze
24
24
  end
@@ -12,7 +12,7 @@ describe 'Command' do
12
12
 
13
13
  let(:payload) do
14
14
  server.with_connection do |connection|
15
- command.send(:final_operation, connection).send(:message, connection).payload.dup.tap do |payload|
15
+ command.send(:final_operation).send(:message, connection).payload.dup.tap do |payload|
16
16
  if payload['request_id'].is_a?(Integer)
17
17
  payload['request_id'] = 42
18
18
  end
@@ -150,28 +150,6 @@ describe 'Command' do
150
150
  expect(payload).to eq(expected_payload)
151
151
  end
152
152
  end
153
-
154
- # Servers using legacy wire protocol message do not have $db in payload.
155
- # $db is added to the payload later when the command monitoring event is
156
- # published.
157
- context 'pre-OP_MSG servers' do
158
- max_server_version '3.4'
159
-
160
- let(:expected_payload) do
161
- {
162
- 'command' => {
163
- 'find' => 'collection_name',
164
- },
165
- 'command_name' => 'find',
166
- 'database_name' => 'foo',
167
- 'request_id' => 42,
168
- }
169
- end
170
-
171
- it 'returns expected payload' do
172
- expect(payload).to eq(expected_payload)
173
- end
174
- end
175
153
  end
176
154
 
177
155
  end
@@ -1773,28 +1773,28 @@ describe Mongo::Client do
1773
1773
  expect do
1774
1774
  client = new_local_client_nmio(['127.0.0.1:27017'],
1775
1775
  :read => {:mode => :bogus})
1776
- end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read option: {"mode"=>:bogus}: mode bogus is not one of recognized modes')
1776
+ end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read preference value: {"mode"=>:bogus}: mode bogus is not one of recognized modes')
1777
1777
  end
1778
1778
 
1779
1779
  it 'rejects bogus read preference as string' do
1780
1780
  expect do
1781
1781
  client = new_local_client_nmio(['127.0.0.1:27017'],
1782
1782
  :read => {:mode => 'bogus'})
1783
- end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read option: {"mode"=>"bogus"}: mode bogus is not one of recognized modes')
1783
+ end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read preference value: {"mode"=>"bogus"}: mode bogus is not one of recognized modes')
1784
1784
  end
1785
1785
 
1786
1786
  it 'rejects read option specified as a string' do
1787
1787
  expect do
1788
1788
  client = new_local_client_nmio(['127.0.0.1:27017'],
1789
1789
  :read => 'primary')
1790
- end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read option: primary: must be a hash')
1790
+ end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read preference value: "primary": the read preference must be specified as a hash: { mode: "primary" }')
1791
1791
  end
1792
1792
 
1793
1793
  it 'rejects read option specified as a symbol' do
1794
1794
  expect do
1795
1795
  client = new_local_client_nmio(['127.0.0.1:27017'],
1796
1796
  :read => :primary)
1797
- end.to raise_error(Mongo::Error::InvalidReadOption, 'Invalid read option: primary: must be a hash')
1797
+ end.to raise_error(Mongo::Error::InvalidReadOption, "Invalid read preference value: :primary: the read preference must be specified as a hash: { mode: :primary }")
1798
1798
  end
1799
1799
  end
1800
1800
  end
@@ -362,6 +362,42 @@ describe Mongo::Collection do
362
362
  expect(result.inserted_ids.size).to eq(2)
363
363
  end
364
364
 
365
+ context 'when an enumerable is used instead of an array' do
366
+
367
+ context 'when the enumerable is not empty' do
368
+
369
+ let(:source_data) do
370
+ [{ name: 'test1' }, { name: 'test2' }]
371
+ end
372
+
373
+ let(:result) do
374
+ authorized_collection.insert_many(source_data.lazy)
375
+ end
376
+
377
+ it 'should accepts them without raising an error' do
378
+ expect { result }.to_not raise_error
379
+ expect(result.inserted_count).to eq(source_data.size)
380
+ end
381
+ end
382
+
383
+ context 'when the enumerable is empty' do
384
+
385
+ let(:source_data) do
386
+ []
387
+ end
388
+
389
+ let(:result) do
390
+ authorized_collection.insert_many(source_data.lazy)
391
+ end
392
+
393
+ it 'should raise ArgumentError' do
394
+ expect do
395
+ result
396
+ end.to raise_error(ArgumentError, /Bulk write requests cannot be empty/)
397
+ end
398
+ end
399
+ end
400
+
365
401
  context 'when a session is provided' do
366
402
 
367
403
  let(:session) do
@@ -4412,4 +4448,24 @@ describe Mongo::Collection do
4412
4448
  expect(result).to be_nil
4413
4449
  end
4414
4450
  end
4451
+
4452
+ context "when creating collection with view_on and pipeline" do
4453
+ before do
4454
+ authorized_client["my_view"].drop
4455
+ authorized_collection.insert_one({ bar: "here!" })
4456
+ authorized_client["my_view",
4457
+ view_on: authorized_collection.name,
4458
+ pipeline: [ { :'$project' => { "baz": "$bar" } } ]
4459
+ ].create
4460
+ end
4461
+
4462
+ it "the view has a document" do
4463
+ expect(authorized_client["my_view"].find.to_a.length).to eq(1)
4464
+ end
4465
+
4466
+ it "applies the pipeline" do
4467
+ expect(authorized_client["my_view"].find.first).to have_key("baz")
4468
+ expect(authorized_client["my_view"].find.first["baz"]).to eq("here!")
4469
+ end
4470
+ end
4415
4471
  end
@@ -647,7 +647,11 @@ describe Mongo::Collection do
647
647
  context 'when the collection is capped' do
648
648
 
649
649
  let(:collection) do
650
- described_class.new(database, :specs, :capped => true, :size => 1024)
650
+ described_class.new(database, :specs, :capped => true, :size => 4096, :max => 512)
651
+ end
652
+
653
+ let(:collstats) do
654
+ database.read_command(:collstats => :specs).documents.first
651
655
  end
652
656
 
653
657
  before do
@@ -658,6 +662,12 @@ describe Mongo::Collection do
658
662
  it 'returns true' do
659
663
  expect(collection).to be_capped
660
664
  end
665
+
666
+ it "applies the options" do
667
+ expect(collstats["capped"]).to be true
668
+ expect(collstats["max"]).to eq(512)
669
+ expect(collstats["maxSize"]).to eq(4096)
670
+ end
661
671
  end
662
672
 
663
673
  context 'when the collection is not capped' do
@@ -33,7 +33,6 @@ describe Mongo::Crypt::KMS do
33
33
  %i(
34
34
  ssl_verify_certificate
35
35
  ssl_verify_hostname
36
- ssl_verify_ocsp_endpoint
37
36
  ).each do |insecure_opt|
38
37
  expect {
39
38
  Mongo::Crypt::KMS::Validations.validate_tls_options(
@@ -46,14 +45,18 @@ describe Mongo::Crypt::KMS do
46
45
  end
47
46
 
48
47
  it 'allows valid options' do
49
- options = {
50
- aws: {
51
- ssl: true,
52
- ssl_cert_string: 'Content is not validated',
53
-
54
- }
55
- }
48
+ expect do
49
+ Mongo::Crypt::KMS::Validations.validate_tls_options(
50
+ {
51
+ aws: {
52
+ ssl: true,
53
+ ssl_cert_string: 'Content is not validated',
54
+ ssl_verify_ocsp_endpoint: false
55
+ }
56
+ }
57
+ )
58
+ end.not_to raise_error
56
59
  end
57
60
  end
58
61
  end
59
- end
62
+ end
data.tar.gz.sig CHANGED
Binary file