mongo 2.18.1 → 2.18.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +1 -1
  4. data/lib/mongo/bulk_write.rb +6 -4
  5. data/lib/mongo/client.rb +1 -1
  6. data/lib/mongo/collection/view/iterable.rb +15 -0
  7. data/lib/mongo/collection/view/writable.rb +0 -2
  8. data/lib/mongo/collection/view.rb +1 -0
  9. data/lib/mongo/collection.rb +150 -45
  10. data/lib/mongo/crypt/auto_encrypter.rb +1 -0
  11. data/lib/mongo/crypt/explicit_encrypter.rb +1 -0
  12. data/lib/mongo/crypt/kms.rb +0 -1
  13. data/lib/mongo/crypt.rb +11 -0
  14. data/lib/mongo/error/invalid_read_option.rb +1 -1
  15. data/lib/mongo/grid/file/chunk.rb +2 -1
  16. data/lib/mongo/grid/file/info.rb +2 -1
  17. data/lib/mongo/operation/aggregate.rb +1 -2
  18. data/lib/mongo/operation/collections_info.rb +3 -15
  19. data/lib/mongo/operation/command.rb +1 -2
  20. data/lib/mongo/operation/count.rb +1 -2
  21. data/lib/mongo/operation/create.rb +1 -2
  22. data/lib/mongo/operation/create_index.rb +1 -2
  23. data/lib/mongo/operation/create_user.rb +1 -2
  24. data/lib/mongo/operation/delete.rb +0 -1
  25. data/lib/mongo/operation/distinct.rb +1 -2
  26. data/lib/mongo/operation/drop.rb +1 -2
  27. data/lib/mongo/operation/drop_database.rb +1 -2
  28. data/lib/mongo/operation/drop_index.rb +1 -2
  29. data/lib/mongo/operation/explain.rb +1 -3
  30. data/lib/mongo/operation/find/builder.rb +0 -1
  31. data/lib/mongo/operation/find.rb +1 -3
  32. data/lib/mongo/operation/get_more.rb +1 -3
  33. data/lib/mongo/operation/indexes.rb +1 -17
  34. data/lib/mongo/operation/insert.rb +0 -1
  35. data/lib/mongo/operation/kill_cursors.rb +1 -2
  36. data/lib/mongo/operation/list_collections.rb +1 -2
  37. data/lib/mongo/operation/map_reduce.rb +1 -2
  38. data/lib/mongo/operation/parallel_scan.rb +1 -2
  39. data/lib/mongo/operation/remove_user.rb +1 -2
  40. data/lib/mongo/operation/shared/{polymorphic_operation.rb → op_msg_executable.rb} +11 -6
  41. data/lib/mongo/operation/update.rb +0 -1
  42. data/lib/mongo/operation/update_user.rb +1 -2
  43. data/lib/mongo/operation/users_info.rb +1 -2
  44. data/lib/mongo/operation/write_command.rb +1 -2
  45. data/lib/mongo/operation.rb +1 -3
  46. data/lib/mongo/protocol/bit_vector.rb +3 -1
  47. data/lib/mongo/protocol/caching_hash.rb +3 -20
  48. data/lib/mongo/protocol/message.rb +4 -8
  49. data/lib/mongo/protocol/msg.rb +1 -0
  50. data/lib/mongo/protocol/serializers.rb +24 -17
  51. data/lib/mongo/protocol.rb +0 -3
  52. data/lib/mongo/query_cache.rb +20 -20
  53. data/lib/mongo/server/app_metadata/environment.rb +255 -0
  54. data/lib/mongo/server/app_metadata/truncator.rb +142 -0
  55. data/lib/mongo/server/app_metadata.rb +29 -42
  56. data/lib/mongo/session.rb +1 -1
  57. data/lib/mongo/version.rb +1 -1
  58. data/spec/integration/command_spec.rb +1 -23
  59. data/spec/integration/connection/faas_env_spec.rb +63 -0
  60. data/spec/integration/find_options_spec.rb +227 -0
  61. data/spec/integration/ocsp_verifier_spec.rb +1 -1
  62. data/spec/lite_spec_helper.rb +9 -0
  63. data/spec/mongo/address_spec.rb +1 -1
  64. data/spec/mongo/client_construction_spec.rb +7 -7
  65. data/spec/mongo/client_spec.rb +1 -9
  66. data/spec/mongo/cluster_spec.rb +2 -2
  67. data/spec/mongo/collection_crud_spec.rb +56 -0
  68. data/spec/mongo/collection_spec.rb +11 -1
  69. data/spec/mongo/crypt/kms_spec.rb +12 -9
  70. data/spec/mongo/crypt_spec.rb +21 -0
  71. data/spec/mongo/index/view_spec.rb +1 -0
  72. data/spec/mongo/protocol/caching_hash_spec.rb +0 -45
  73. data/spec/mongo/protocol/msg_spec.rb +2 -4
  74. data/spec/mongo/server/app_metadata/environment_spec.rb +193 -0
  75. data/spec/mongo/server/app_metadata/truncator_spec.rb +158 -0
  76. data/spec/mongo/server/app_metadata_spec.rb +33 -47
  77. data/spec/mongo/socket/ssl_spec.rb +2 -8
  78. data/spec/runners/crud/requirement.rb +2 -2
  79. data/spec/shared/lib/mrss/docker_runner.rb +4 -0
  80. data/spec/shared/lib/mrss/lite_constraints.rb +8 -0
  81. data/spec/shared/lib/mrss/server_version_registry.rb +16 -23
  82. data/spec/shared/share/Dockerfile.erb +24 -19
  83. data/spec/shared/shlib/server.sh +31 -7
  84. data/spec/shared/shlib/set_env.sh +4 -4
  85. data/spec/solo/clean_exit_spec.rb +3 -10
  86. data/spec/spec_tests/data/change_streams_unified/change-streams-showExpandedEvents.yml +15 -6
  87. data/spec/spec_tests/data/command_monitoring_unified/redacted-commands.yml +8 -0
  88. data/spec/support/aws_utils.rb +3 -3
  89. data/spec/support/certificates/atlas-ocsp-ca.crt +67 -67
  90. data/spec/support/certificates/atlas-ocsp.crt +103 -103
  91. data/spec/support/shared/app_metadata.rb +14 -2
  92. data.tar.gz.sig +0 -0
  93. metadata +1203 -1239
  94. metadata.gz.sig +0 -0
  95. data/lib/mongo/operation/aggregate/command.rb +0 -55
  96. data/lib/mongo/operation/collections_info/command.rb +0 -48
  97. data/lib/mongo/operation/command/command.rb +0 -41
  98. data/lib/mongo/operation/count/command.rb +0 -47
  99. data/lib/mongo/operation/create/command.rb +0 -47
  100. data/lib/mongo/operation/create_index/command.rb +0 -61
  101. data/lib/mongo/operation/create_user/command.rb +0 -46
  102. data/lib/mongo/operation/delete/command.rb +0 -52
  103. data/lib/mongo/operation/distinct/command.rb +0 -47
  104. data/lib/mongo/operation/drop/command.rb +0 -41
  105. data/lib/mongo/operation/drop_database/command.rb +0 -41
  106. data/lib/mongo/operation/drop_index/command.rb +0 -45
  107. data/lib/mongo/operation/explain/command.rb +0 -58
  108. data/lib/mongo/operation/explain/legacy.rb +0 -52
  109. data/lib/mongo/operation/find/builder/legacy.rb +0 -123
  110. data/lib/mongo/operation/find/command.rb +0 -51
  111. data/lib/mongo/operation/find/legacy/result.rb +0 -46
  112. data/lib/mongo/operation/find/legacy.rb +0 -52
  113. data/lib/mongo/operation/get_more/command.rb +0 -43
  114. data/lib/mongo/operation/get_more/legacy.rb +0 -39
  115. data/lib/mongo/operation/indexes/command.rb +0 -42
  116. data/lib/mongo/operation/indexes/legacy.rb +0 -48
  117. data/lib/mongo/operation/insert/command.rb +0 -55
  118. data/lib/mongo/operation/kill_cursors/command.rb +0 -48
  119. data/lib/mongo/operation/list_collections/command.rb +0 -46
  120. data/lib/mongo/operation/map_reduce/command.rb +0 -51
  121. data/lib/mongo/operation/parallel_scan/command.rb +0 -57
  122. data/lib/mongo/operation/remove_user/command.rb +0 -46
  123. data/lib/mongo/operation/shared/op_msg_or_command.rb +0 -41
  124. data/lib/mongo/operation/shared/op_msg_or_find_command.rb +0 -44
  125. data/lib/mongo/operation/update/command.rb +0 -53
  126. data/lib/mongo/operation/update_user/command.rb +0 -45
  127. data/lib/mongo/operation/users_info/command.rb +0 -46
  128. data/lib/mongo/operation/write_command/command.rb +0 -51
  129. data/lib/mongo/protocol/delete.rb +0 -172
  130. data/lib/mongo/protocol/insert.rb +0 -181
  131. data/lib/mongo/protocol/update.rb +0 -214
  132. data/spec/mongo/operation/delete/command_spec.rb +0 -115
  133. data/spec/mongo/operation/find/legacy_spec.rb +0 -131
  134. data/spec/mongo/operation/get_more_spec.rb +0 -63
  135. data/spec/mongo/operation/insert/command_spec.rb +0 -118
  136. data/spec/mongo/operation/update/command_spec.rb +0 -122
  137. data/spec/mongo/protocol/delete_spec.rb +0 -185
  138. data/spec/mongo/protocol/insert_spec.rb +0 -179
  139. data/spec/mongo/protocol/update_spec.rb +0 -204
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 664d381d4746fb4ff6282069f909a91a58f497220bae57656c265f52c5d99040
4
- data.tar.gz: 85fa7fbf071c3e8fc4c1beb2215b3297a3af560130204dbd0f916adb272987f7
3
+ metadata.gz: 0c36a5a34e34ad90dc310f1151d98257f36c6c2bbea07282963f631f06a450eb
4
+ data.tar.gz: 220b2abd528a4f540d08cf08e78e256be845ae5b9bcf41f52f92ce9c98e554b5
5
5
  SHA512:
6
- metadata.gz: 2dcf66e773da4e2bdaf0a22d15a06eadbc5ab2bccffc29f012e2ae863e8148b597550ee680dc2556b40408f4c759b78b159b678cf494cf619c0975044d72d662
7
- data.tar.gz: c120607792132931a54511db0a4ef62653393138e9da3fcf0ca0f0a85fde3aefe6b04782fd09125b0fe3085e50c66b1cd2f6e0c4743ae40e7094dc8e7892587a
6
+ metadata.gz: 8fd8cdeee661a65f74b3825db234492357bb82f3b4ec595f0df9477e0b03f62ac093c33d31a0ff7b766868556662b32ee74c3ff87be379cda4bc5363e2e37b0e
7
+ data.tar.gz: 2d202097305e6b8fa1fba5541fe8d6d630f1beb96cef753294d16ccfbaa1d114547208868d16fc3b48a9e5b897144edff580bcb8edab28123a089f32ded1340e
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -5,7 +5,7 @@ MongoDB Ruby Driver
5
5
 
6
6
  The officially supported Ruby driver for [MongoDB](https://www.mongodb.org/).
7
7
 
8
- The Ruby driver supports Ruby 2.5-3.0 and JRuby 9.2.
8
+ The Ruby driver supports Ruby 2.5-3.2 and JRuby 9.2-9.3.
9
9
 
10
10
  ## Documentation
11
11
 
@@ -115,7 +115,8 @@ module Mongo
115
115
  # )
116
116
  #
117
117
  # @param [ Mongo::Collection ] collection The collection.
118
- # @param [ Array<Hash, BSON::Document> ] requests The requests, cannot be empty.
118
+ # @param [ Enumerable<Hash, BSON::Document> ] requests The requests,
119
+ # cannot be empty.
119
120
  # @param [ Hash, BSON::Document ] options The options.
120
121
  #
121
122
  # @since 2.1.0
@@ -330,10 +331,9 @@ module Mongo
330
331
  # ArgumentError ]
331
332
  # if the document is invalid.
332
333
  def validate_requests!
333
- if @requests.empty?
334
- raise ArgumentError, "Bulk write requests cannot be empty"
335
- end
334
+ requests_empty = true
336
335
  @requests.each do |req|
336
+ requests_empty = false
337
337
  if op = req.keys.first
338
338
  if [:update_one, :update_many].include?(op)
339
339
  if doc = maybe_first(req.dig(op, :update))
@@ -359,6 +359,8 @@ module Mongo
359
359
  end
360
360
  end
361
361
  end
362
+ end.tap do
363
+ raise ArgumentError, "Bulk write requests cannot be empty" if requests_empty
362
364
  end
363
365
  end
364
366
 
data/lib/mongo/client.rb CHANGED
@@ -1570,7 +1570,7 @@ module Mongo
1570
1570
  # for custom classes implementing key access ([]).
1571
1571
  # Instead reject common cases of strings and symbols.
1572
1572
  if read.is_a?(String) || read.is_a?(Symbol)
1573
- raise Error::InvalidReadOption.new(read, 'must be a hash')
1573
+ raise Error::InvalidReadOption.new(read, "the read preference must be specified as a hash: { mode: #{read.inspect} }")
1574
1574
  end
1575
1575
 
1576
1576
  if mode = read[:mode]
@@ -185,6 +185,8 @@ module Mongo
185
185
  collection.client.log_warn("The :oplog_replay option is deprecated and ignored by MongoDB 4.4 and later")
186
186
  end
187
187
 
188
+ maybe_set_tailable_options(spec)
189
+
188
190
  if explained?
189
191
  spec[:explain] = options[:explain]
190
192
  Operation::Explain.new(spec)
@@ -200,6 +202,19 @@ module Mongo
200
202
  def use_query_cache?
201
203
  QueryCache.enabled? && !collection.system_collection?
202
204
  end
205
+
206
+ # Add tailable cusror options to the command specifiction if needed.
207
+ #
208
+ # @param [ Hash ] spec The command specification.
209
+ def maybe_set_tailable_options(spec)
210
+ case cursor_type
211
+ when :tailable
212
+ spec[:tailable] = true
213
+ when :tailable_await
214
+ spec[:tailable] = true
215
+ spec[:await_data] = true
216
+ end
217
+ end
203
218
  end
204
219
  end
205
220
  end
@@ -98,8 +98,6 @@ module Mongo
98
98
  end.first&.fetch('value', nil)
99
99
  end
100
100
 
101
- # db['users'].bulk_write([{insert_one: {x: 1}}, {insert_one: {x: 2}}])
102
-
103
101
  # Finds a single document and replaces it.
104
102
  #
105
103
  # @example Find a document and replace it, returning the original.
@@ -127,6 +127,7 @@ module Mongo
127
127
  # return in each response from MongoDB.
128
128
  # @option options [ Hash ] :collation The collation to use.
129
129
  # @option options [ String ] :comment Associate a comment with the query.
130
+ # @option options [ :tailable, :tailable_await ] :cursor_type The type of cursor to use.
130
131
  # @option options [ Hash ] :explain Execute an explain with the provided
131
132
  # explain options (known options are :verbose and :verbosity) rather
132
133
  # than a find.
@@ -83,7 +83,7 @@ module Mongo
83
83
  #
84
84
  # @param [ Object ] other The object to check.
85
85
  #
86
- # @return [ true, false ] If the objects are equal.
86
+ # @return [ true | false ] If the objects are equal.
87
87
  #
88
88
  # @since 2.0.0
89
89
  def ==(other)
@@ -100,19 +100,59 @@ module Mongo
100
100
  # @param [ String, Symbol ] name The collection name.
101
101
  # @param [ Hash ] options The collection options.
102
102
  #
103
- # @option options [ Hash ] :write Deprecated. Equivalent to :write_concern
103
+ # @option opts [ true | false ] :capped Create a fixed-sized collection.
104
+ # @option opts [ Hash ] :change_stream_pre_and_post_images Used to enable
105
+ # pre- and post-images on the created collection.
106
+ # The hash may have the following items:
107
+ # - *:enabled* -- true or false.
108
+ # @option opts [ Hash ] :clustered_index Create a clustered index.
109
+ # This option specifies how this collection should be clustered on _id.
110
+ # The hash may have the following items:
111
+ # - *:key* -- The clustered index key field. Must be set to { _id: 1 }.
112
+ # - *:unique* -- Must be set to true. The collection will not accept
113
+ # inserted or updated documents where the clustered index key value
114
+ # matches an existing value in the index.
115
+ # - *:name* -- Optional. A name that uniquely identifies the clustered index.
116
+ # @option opts [ Hash ] :collation The collation to use.
117
+ # @option opts [ Hash ] :encrypted_fields Hash describing encrypted fields
118
+ # for queryable encryption.
119
+ # @option opts [ Integer ] :expire_after Number indicating
120
+ # after how many seconds old time-series data should be deleted.
121
+ # @option opts [ Integer ] :max The maximum number of documents in a
122
+ # capped collection. The size limit takes precedents over max.
123
+ # @option opts [ Array<Hash> ] :pipeline An array of pipeline stages.
124
+ # A view will be created by applying this pipeline to the view_on
125
+ # collection or view.
126
+ # @option options [ Hash ] :read_concern The read concern options hash,
127
+ # with the following optional keys:
128
+ # - *:level* -- the read preference level as a symbol; valid values
129
+ # are *:local*, *:majority*, and *:snapshot*
130
+ # @option options [ Hash ] :read The read preference options.
131
+ # The hash may have the following items:
132
+ # - *:mode* -- read preference specified as a symbol; valid values are
133
+ # *:primary*, *:primary_preferred*, *:secondary*, *:secondary_preferred*
134
+ # and *:nearest*.
135
+ # - *:tag_sets* -- an array of hashes.
136
+ # - *:local_threshold*.
137
+ # @option opts [ Session ] :session The session to use for the operation.
138
+ # @option opts [ Integer ] :size The size of the capped collection.
139
+ # @option opts [ Hash ] :time_series Create a time-series collection.
140
+ # The hash may have the following items:
141
+ # - *:timeField* -- The name of the field which contains the date in each
142
+ # time series document.
143
+ # - *:metaField* -- The name of the field which contains metadata in each
144
+ # time series document.
145
+ # - *:granularity* -- Set the granularity to the value that is the closest
146
+ # match to the time span between consecutive incoming measurements.
147
+ # Possible values are "seconds" (default), "minutes", and "hours".
148
+ # @option opts [ Hash ] :validator Hash describing document validation
149
+ # options for the collection.
150
+ # @option opts [ String ] :view_on The name of the source collection or
151
+ # view from which to create a view.
152
+ # @option opts [ Hash ] :write Deprecated. Equivalent to :write_concern
104
153
  # option.
105
- # @option options [ Hash ] :write_concern The write concern options.
154
+ # @option opts [ Hash ] :write_concern The write concern options.
106
155
  # Can be :w => Integer|String, :fsync => Boolean, :j => Boolean.
107
- # @option options [ Hash ] :time_series Create a time-series collection.
108
- # See https://mongodb.com/docs/manual/core/timeseries-collections/ for more
109
- # information about time-series collection.
110
- # @option options [ Integer ] :expire_after Number indicating
111
- # after how many seconds old time-series data should be deleted.
112
- # @options clustered_index [ Hash ] :clustered_index Create a clustered index.
113
- # This option specifies how this collection should be clustered on _id.
114
- # See https://www.mongodb.com/docs/v5.3/reference/method/db.createCollection/#std-label-db.createCollection.clusteredIndex
115
- # for more information about this option.
116
156
  #
117
157
  # @since 2.0.0
118
158
  def initialize(database, name, options = {})
@@ -204,17 +244,37 @@ module Mongo
204
244
  wc
205
245
  end
206
246
 
207
- # Provides a new collection with either a new read preference or new write concern
208
- # merged over the existing read preference / write concern.
247
+ # Provides a new collection with either a new read preference, new read
248
+ # concern or new write concern merged over the existing read preference /
249
+ # read concern / write concern.
209
250
  #
210
251
  # @example Get a collection with a changed read preference.
211
252
  # collection.with(read: { mode: :primary_preferred })
253
+
254
+ # @example Get a collection with a changed read concern.
255
+ # collection.with(read_concern: { level: :majority })
212
256
  #
213
257
  # @example Get a collection with a changed write concern.
214
258
  # collection.with(write_concern: { w: 3 })
215
-
259
+ #
216
260
  # @param [ Hash ] new_options The new options to use.
217
261
  #
262
+ # @option new_options [ Hash ] :read The read preference options.
263
+ # The hash may have the following items:
264
+ # - *:mode* -- read preference specified as a symbol; valid values are
265
+ # *:primary*, *:primary_preferred*, *:secondary*, *:secondary_preferred*
266
+ # and *:nearest*.
267
+ # - *:tag_sets* -- an array of hashes.
268
+ # - *:local_threshold*.
269
+ # @option new_options [ Hash ] :read_concern The read concern options hash,
270
+ # with the following optional keys:
271
+ # - *:level* -- the read preference level as a symbol; valid values
272
+ # are *:local*, *:majority*, and *:snapshot*
273
+ # @option new_options [ Hash ] :write Deprecated. Equivalent to :write_concern
274
+ # option.
275
+ # @option new_options [ Hash ] :write_concern The write concern options.
276
+ # Can be :w => Integer|String, :fsync => Boolean, :j => Boolean.
277
+ #
218
278
  # @return [ Mongo::Collection ] A new collection instance.
219
279
  #
220
280
  # @since 2.1.0
@@ -237,7 +297,7 @@ module Mongo
237
297
  # @example Is the collection capped?
238
298
  # collection.capped?
239
299
  #
240
- # @return [ true, false ] If the collection is capped.
300
+ # @return [ true | false ] If the collection is capped.
241
301
  #
242
302
  # @since 2.0.0
243
303
  def capped?
@@ -251,17 +311,48 @@ module Mongo
251
311
  #
252
312
  # @param [ Hash ] opts The options for the create operation.
253
313
  #
254
- # @option opts [ Session ] :session The session to use for the operation.
255
- # @option opts [ Hash ] :write_concern The write concern options.
256
- # @option opts [ Hash ] :time_series Create a time-series collection.
257
- # @option opts [ Integer ] :expire_after Number indicating
258
- # after how many seconds old time-series data should be deleted.
314
+ # @option opts [ true | false ] :capped Create a fixed-sized collection.
259
315
  # @option opts [ Hash ] :change_stream_pre_and_post_images Used to enable
260
316
  # pre- and post-images on the created collection.
317
+ # The hash may have the following items:
318
+ # - *:enabled* -- true or false.
319
+ # @option opts [ Hash ] :clustered_index Create a clustered index.
320
+ # This option specifies how this collection should be clustered on _id.
321
+ # The hash may have the following items:
322
+ # - *:key* -- The clustered index key field. Must be set to { _id: 1 }.
323
+ # - *:unique* -- Must be set to true. The collection will not accept
324
+ # inserted or updated documents where the clustered index key value
325
+ # matches an existing value in the index.
326
+ # - *:name* -- Optional. A name that uniquely identifies the clustered index.
327
+ # @option opts [ Hash ] :collation The collation to use.
261
328
  # @option opts [ Hash ] :encrypted_fields Hash describing encrypted fields
262
329
  # for queryable encryption.
330
+ # @option opts [ Integer ] :expire_after Number indicating
331
+ # after how many seconds old time-series data should be deleted.
332
+ # @option opts [ Integer ] :max The maximum number of documents in a
333
+ # capped collection. The size limit takes precedents over max.
334
+ # @option opts [ Array<Hash> ] :pipeline An array of pipeline stages.
335
+ # A view will be created by applying this pipeline to the view_on
336
+ # collection or view.
337
+ # @option opts [ Session ] :session The session to use for the operation.
338
+ # @option opts [ Integer ] :size The size of the capped collection.
339
+ # @option opts [ Hash ] :time_series Create a time-series collection.
340
+ # The hash may have the following items:
341
+ # - *:timeField* -- The name of the field which contains the date in each
342
+ # time series document.
343
+ # - *:metaField* -- The name of the field which contains metadata in each
344
+ # time series document.
345
+ # - *:granularity* -- Set the granularity to the value that is the closest
346
+ # match to the time span between consecutive incoming measurements.
347
+ # Possible values are "seconds" (default), "minutes", and "hours".
263
348
  # @option opts [ Hash ] :validator Hash describing document validation
264
349
  # options for the collection.
350
+ # @option opts [ String ] :view_on The name of the source collection or
351
+ # view from which to create a view.
352
+ # @option opts [ Hash ] :write Deprecated. Equivalent to :write_concern
353
+ # option.
354
+ # @option opts [ Hash ] :write_concern The write concern options.
355
+ # Can be :w => Integer|String, :fsync => Boolean, :j => Boolean.
265
356
  #
266
357
  # @return [ Result ] The result of the command.
267
358
  #
@@ -318,8 +409,10 @@ module Mongo
318
409
  #
319
410
  # @param [ Hash ] opts The options for the drop operation.
320
411
  #
321
- # @option options [ Session ] :session The session to use for the operation.
412
+ # @option opts [ Session ] :session The session to use for the operation.
322
413
  # @option opts [ Hash ] :write_concern The write concern options.
414
+ # @option opts [ Hash | nil ] :encrypted_fields Encrypted fields hash that
415
+ # was provided to `create` collection helper.
323
416
  #
324
417
  # @return [ Result ] The result of the command.
325
418
  #
@@ -356,27 +449,27 @@ module Mongo
356
449
  # @param [ Hash ] filter The filter to use in the find.
357
450
  # @param [ Hash ] options The options for the find.
358
451
  #
359
- # @option options [ true, false ] :allow_disk_use When set to true, the
452
+ # @option options [ true | false ] :allow_disk_use When set to true, the
360
453
  # server can write temporary data to disk while executing the find
361
454
  # operation. This option is only available on MongoDB server versions
362
455
  # 4.4 and newer.
363
- # @option options [ true, false ] :allow_partial_results Allows the query to get partial
456
+ # @option options [ true | false ] :allow_partial_results Allows the query to get partial
364
457
  # results if some shards are down.
365
458
  # @option options [ Integer ] :batch_size The number of documents returned in each batch
366
459
  # of results from MongoDB.
367
460
  # @option options [ Hash ] :collation The collation to use.
368
- # @option options [ Object ] :comment A user-provided
369
- # comment to attach to this command.
461
+ # @option options [ Object ] :comment A user-provided comment to attach to
462
+ # this command.
370
463
  # @option options [ :tailable, :tailable_await ] :cursor_type The type of cursor to use.
371
464
  # @option options [ Integer ] :limit The max number of docs to return from the query.
372
465
  # @option options [ Integer ] :max_time_ms
373
466
  # The maximum amount of time to allow the query to run, in milliseconds.
374
467
  # @option options [ Hash ] :modifiers A document containing meta-operators modifying the
375
468
  # output or behavior of a query.
376
- # @option options [ true, false ] :no_cursor_timeout The server normally times out idle
469
+ # @option options [ true | false ] :no_cursor_timeout The server normally times out idle
377
470
  # cursors after an inactivity period (10 minutes) to prevent excess memory use.
378
471
  # Set this option to prevent that.
379
- # @option options [ true, false ] :oplog_replay For internal replication
472
+ # @option options [ true | false ] :oplog_replay For internal replication
380
473
  # use only, applications should not set this option.
381
474
  # @option options [ Hash ] :projection The fields to include or exclude from each doc
382
475
  # in the result set.
@@ -402,11 +495,11 @@ module Mongo
402
495
  # @param [ Array<Hash> ] pipeline The aggregation pipeline.
403
496
  # @param [ Hash ] options The aggregation options.
404
497
  #
405
- # @option options [ true, false ] :allow_disk_use Set to true if disk
498
+ # @option options [ true | false ] :allow_disk_use Set to true if disk
406
499
  # usage is allowed during the aggregation.
407
500
  # @option options [ Integer ] :batch_size The number of documents to return
408
501
  # per batch.
409
- # @option options [ true, false ] :bypass_document_validation Whether or
502
+ # @option options [ true | false ] :bypass_document_validation Whether or
410
503
  # not to skip document level validation.
411
504
  # @option options [ Hash ] :collation The collation to use.
412
505
  # @option options [ Object ] :comment A user-provided
@@ -416,7 +509,7 @@ module Mongo
416
509
  # See the server documentation for details.
417
510
  # @option options [ Integer ] :max_time_ms The maximum amount of time in
418
511
  # milliseconds to allow the aggregation to run.
419
- # @option options [ true, false ] :use_cursor Indicates whether the command
512
+ # @option options [ true | false ] :use_cursor Indicates whether the command
420
513
  # will request that the server provide results using a cursor. Note that
421
514
  # as of server version 3.6, aggregations always provide results using a
422
515
  # cursor and this option is therefore not valid.
@@ -642,7 +735,13 @@ module Mongo
642
735
  # @param [ Hash ] document The document to insert.
643
736
  # @param [ Hash ] opts The insert options.
644
737
  #
738
+ # @option opts [ true | false ] :bypass_document_validation Whether or
739
+ # not to skip document level validation.
740
+ # @option opts [ Object ] :comment A user-provided comment to attach to
741
+ # this command.
645
742
  # @option opts [ Session ] :session The session to use for the operation.
743
+ # @option opts [ Hash ] :write_concern The write concern options.
744
+ # Can be :w => Integer, :fsync => Boolean, :j => Boolean.
646
745
  #
647
746
  # @return [ Result ] The database response wrapper.
648
747
  #
@@ -684,12 +783,18 @@ module Mongo
684
783
  # @example Insert documents into the collection.
685
784
  # collection.insert_many([{ name: 'test' }])
686
785
  #
687
- # @param [ Array<Hash> ] documents The documents to insert.
786
+ # @param [ Enumerable<Hash> ] documents The documents to insert.
688
787
  # @param [ Hash ] options The insert options.
689
788
  #
789
+ # @option options [ true | false ] :bypass_document_validation Whether or
790
+ # not to skip document level validation.
791
+ # @option options [ Object ] :comment A user-provided comment to attach to
792
+ # this command.
690
793
  # @option options [ true | false ] :ordered Whether the operations
691
794
  # should be executed in order.
692
795
  # @option options [ Session ] :session The session to use for the operation.
796
+ # @option options [ Hash ] :write_concern The write concern options.
797
+ # Can be :w => Integer, :fsync => Boolean, :j => Boolean.
693
798
  #
694
799
  # @return [ Result ] The database response wrapper.
695
800
  #
@@ -706,14 +811,14 @@ module Mongo
706
811
  # @example Execute a bulk write.
707
812
  # collection.bulk_write(operations, options)
708
813
  #
709
- # @param [ Array<Hash> ] requests The bulk write requests.
814
+ # @param [ Enumerable<Hash> ] requests The bulk write requests.
710
815
  # @param [ Hash ] options The options.
711
816
  #
712
- # @option options [ true, false ] :ordered Whether the operations
817
+ # @option options [ true | false ] :ordered Whether the operations
713
818
  # should be executed in order.
714
819
  # @option options [ Hash ] :write_concern The write concern options.
715
820
  # Can be :w => Integer, :fsync => Boolean, :j => Boolean.
716
- # @option options [ true, false ] :bypass_document_validation Whether or
821
+ # @option options [ true | false ] :bypass_document_validation Whether or
717
822
  # not to skip document level validation.
718
823
  # @option options [ Session ] :session The session to use for the set of operations.
719
824
  # @option options [ Hash ] :let Mapping of variables to use in the command.
@@ -802,9 +907,9 @@ module Mongo
802
907
  # @param [ Hash ] replacement The replacement document..
803
908
  # @param [ Hash ] options The options.
804
909
  #
805
- # @option options [ true, false ] :upsert Whether to upsert if the
910
+ # @option options [ true | false ] :upsert Whether to upsert if the
806
911
  # document doesn't exist.
807
- # @option options [ true, false ] :bypass_document_validation Whether or
912
+ # @option options [ true | false ] :bypass_document_validation Whether or
808
913
  # not to skip document level validation.
809
914
  # @option options [ Hash ] :collation The collation to use.
810
915
  # @option options [ Session ] :session The session to use.
@@ -829,9 +934,9 @@ module Mongo
829
934
  # @param [ Hash | Array<Hash> ] update The update document or pipeline.
830
935
  # @param [ Hash ] options The options.
831
936
  #
832
- # @option options [ true, false ] :upsert Whether to upsert if the
937
+ # @option options [ true | false ] :upsert Whether to upsert if the
833
938
  # document doesn't exist.
834
- # @option options [ true, false ] :bypass_document_validation Whether or
939
+ # @option options [ true | false ] :bypass_document_validation Whether or
835
940
  # not to skip document level validation.
836
941
  # @option options [ Hash ] :collation The collation to use.
837
942
  # @option options [ Array ] :array_filters A set of filters specifying to which array elements
@@ -858,9 +963,9 @@ module Mongo
858
963
  # @param [ Hash | Array<Hash> ] update The update document or pipeline.
859
964
  # @param [ Hash ] options The options.
860
965
  #
861
- # @option options [ true, false ] :upsert Whether to upsert if the
966
+ # @option options [ true | false ] :upsert Whether to upsert if the
862
967
  # document doesn't exist.
863
- # @option options [ true, false ] :bypass_document_validation Whether or
968
+ # @option options [ true | false ] :bypass_document_validation Whether or
864
969
  # not to skip document level validation.
865
970
  # @option options [ Hash ] :collation The collation to use.
866
971
  # @option options [ Array ] :array_filters A set of filters specifying to which array elements
@@ -927,8 +1032,8 @@ module Mongo
927
1032
  # @option options [ Hash ] :sort The key and direction pairs by which the result set
928
1033
  # will be sorted.
929
1034
  # @option options [ Symbol ] :return_document Either :before or :after.
930
- # @option options [ true, false ] :upsert Whether to upsert if the document doesn't exist.
931
- # @option options [ true, false ] :bypass_document_validation Whether or
1035
+ # @option options [ true | false ] :upsert Whether to upsert if the document doesn't exist.
1036
+ # @option options [ true | false ] :bypass_document_validation Whether or
932
1037
  # not to skip document level validation.
933
1038
  # @option options [ Hash ] :write_concern The write concern options.
934
1039
  # Defaults to the collection's write concern.
@@ -967,8 +1072,8 @@ module Mongo
967
1072
  # @option options [ Hash ] :sort The key and direction pairs by which the result set
968
1073
  # will be sorted.
969
1074
  # @option options [ Symbol ] :return_document Either :before or :after.
970
- # @option options [ true, false ] :upsert Whether to upsert if the document doesn't exist.
971
- # @option options [ true, false ] :bypass_document_validation Whether or
1075
+ # @option options [ true | false ] :upsert Whether to upsert if the document doesn't exist.
1076
+ # @option options [ true | false ] :bypass_document_validation Whether or
972
1077
  # not to skip document level validation.
973
1078
  # @option options [ Hash ] :write_concern The write concern options.
974
1079
  # Defaults to the collection's write concern.
@@ -91,6 +91,7 @@ module Mongo
91
91
  # @raise [ ArgumentError ] If required options are missing or incorrectly
92
92
  # formatted.
93
93
  def initialize(options)
94
+ Crypt.validate_ffi!
94
95
  # Note that this call may eventually, via other method invocations,
95
96
  # create additional clients which have to be cleaned up.
96
97
  @options = set_default_options(options).freeze
@@ -36,6 +36,7 @@ module Mongo
36
36
  # should be hashes of TLS connection options. The options are equivalent
37
37
  # to TLS connection options of Mongo::Client.
38
38
  def initialize(key_vault_client, key_vault_namespace, kms_providers, kms_tls_options)
39
+ Crypt.validate_ffi!
39
40
  @crypt_handle = Handle.new(
40
41
  kms_providers,
41
42
  kms_tls_options,
@@ -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/crypt.rb CHANGED
@@ -35,5 +35,16 @@ module Mongo
35
35
  autoload(:ExplicitEncrypter, 'mongo/crypt/explicit_encrypter')
36
36
  autoload(:AutoEncrypter, 'mongo/crypt/auto_encrypter')
37
37
  autoload(:KMS, 'mongo/crypt/kms')
38
+
39
+ def validate_ffi!
40
+ return if defined?(FFI)
41
+
42
+ require 'ffi'
43
+ rescue LoadError => e
44
+ raise Error::UnmetDependency, 'Cannot enable encryption because the ffi gem ' \
45
+ "has not been installed. Add \"gem 'ffi'\" to your Gemfile and run " \
46
+ "\"bundle install\" to install the gem. (#{e.class}: #{e})"
47
+ end
48
+ module_function :validate_ffi!
38
49
  end
39
50
  end
@@ -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
@@ -133,11 +133,12 @@ module Mongo
133
133
  #
134
134
  # @param [ BSON::ByteBuffer ] buffer The encoded BSON buffer to append to.
135
135
  # @param [ true, false ] validating_keys Whether keys should be validated when serializing.
136
+ # This option is deprecated and will not be used. It will removed in version 3.0.
136
137
  #
137
138
  # @return [ String ] The raw BSON data.
138
139
  #
139
140
  # @since 2.0.0
140
- def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = BSON::Config.validating_keys?)
141
+ def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil)
141
142
  document.to_bson(buffer)
142
143
  end
143
144
 
@@ -228,11 +228,12 @@ module Mongo
228
228
  #
229
229
  # @param [ BSON::ByteBuffer ] buffer The encoded BSON buffer to append to.
230
230
  # @param [ true, false ] validating_keys Whether keys should be validated when serializing.
231
+ # This option is deprecated and will not be used. It will removed in version 3.0.
231
232
  #
232
233
  # @return [ String ] The raw BSON data.
233
234
  #
234
235
  # @since 2.0.0
235
- def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = BSON::Config.validating_keys?)
236
+ def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil)
236
237
  if @client_md5 && !document[:md5]
237
238
  document[:md5] = @client_md5.hexdigest
238
239
  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