mongo 2.13.3 → 2.14.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/mongo/address/ipv4.rb +1 -1
- data/lib/mongo/address/ipv6.rb +1 -1
- data/lib/mongo/address.rb +1 -1
- data/lib/mongo/bulk_write.rb +17 -0
- data/lib/mongo/caching_cursor.rb +74 -0
- data/lib/mongo/client.rb +47 -8
- data/lib/mongo/cluster/topology/single.rb +1 -1
- data/lib/mongo/cluster.rb +3 -3
- data/lib/mongo/collection/view/aggregation.rb +25 -4
- data/lib/mongo/collection/view/builder/find_command.rb +38 -18
- data/lib/mongo/collection/view/explainable.rb +27 -8
- data/lib/mongo/collection/view/iterable.rb +72 -12
- data/lib/mongo/collection/view/readable.rb +12 -2
- data/lib/mongo/collection/view/writable.rb +15 -1
- data/lib/mongo/collection/view.rb +24 -20
- data/lib/mongo/collection.rb +26 -2
- data/lib/mongo/crypt/encryption_io.rb +6 -6
- data/lib/mongo/cursor.rb +1 -0
- data/lib/mongo/database/view.rb +1 -1
- data/lib/mongo/database.rb +8 -14
- data/lib/mongo/error/invalid_read_concern.rb +28 -0
- data/lib/mongo/error/server_certificate_revoked.rb +22 -0
- data/lib/mongo/error/unsupported_option.rb +14 -12
- data/lib/mongo/error.rb +2 -0
- data/lib/mongo/grid/fs_bucket.rb +37 -37
- data/lib/mongo/lint.rb +2 -1
- data/lib/mongo/logger.rb +3 -3
- data/lib/mongo/operation/aggregate/result.rb +9 -8
- data/lib/mongo/operation/collections_info/command.rb +0 -5
- data/lib/mongo/operation/collections_info/result.rb +3 -16
- data/lib/mongo/operation/delete/bulk_result.rb +2 -0
- data/lib/mongo/operation/delete/result.rb +3 -0
- data/lib/mongo/operation/explain/command.rb +4 -0
- data/lib/mongo/operation/explain/legacy.rb +4 -0
- data/lib/mongo/operation/explain/op_msg.rb +6 -0
- data/lib/mongo/operation/explain/result.rb +3 -0
- data/lib/mongo/operation/find/legacy/result.rb +2 -0
- data/lib/mongo/operation/find/result.rb +3 -0
- data/lib/mongo/operation/get_more/result.rb +3 -0
- data/lib/mongo/operation/indexes/result.rb +5 -0
- data/lib/mongo/operation/insert/bulk_result.rb +5 -0
- data/lib/mongo/operation/insert/result.rb +5 -0
- data/lib/mongo/operation/list_collections/result.rb +5 -0
- data/lib/mongo/operation/map_reduce/result.rb +10 -0
- data/lib/mongo/operation/parallel_scan/command.rb +2 -1
- data/lib/mongo/operation/parallel_scan/result.rb +4 -0
- data/lib/mongo/operation/result.rb +35 -6
- data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
- data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
- data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
- data/lib/mongo/operation/shared/executable.rb +1 -0
- data/lib/mongo/operation/shared/idable.rb +2 -1
- data/lib/mongo/operation/shared/limited.rb +1 -0
- data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
- data/lib/mongo/operation/shared/read_preference_supported.rb +36 -38
- data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
- data/lib/mongo/operation/shared/sessions_supported.rb +3 -3
- data/lib/mongo/operation/shared/specifiable.rb +1 -0
- data/lib/mongo/operation/shared/write.rb +1 -0
- data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
- data/lib/mongo/operation/update/legacy/result.rb +7 -0
- data/lib/mongo/operation/update/result.rb +8 -0
- data/lib/mongo/operation/users_info/result.rb +3 -0
- data/lib/mongo/operation.rb +2 -0
- data/lib/mongo/protocol/msg.rb +2 -2
- data/lib/mongo/protocol/query.rb +11 -11
- data/lib/mongo/query_cache.rb +242 -0
- data/lib/mongo/retryable.rb +8 -1
- data/lib/mongo/server/connection_common.rb +2 -2
- data/lib/mongo/server/connection_pool.rb +3 -0
- data/lib/mongo/server/monitor/connection.rb +3 -3
- data/lib/mongo/server/monitor.rb +1 -1
- data/lib/mongo/server/pending_connection.rb +2 -2
- data/lib/mongo/server/push_monitor.rb +1 -1
- data/lib/mongo/server.rb +5 -1
- data/lib/mongo/server_selector/base.rb +5 -1
- data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
- data/lib/mongo/session.rb +3 -0
- data/lib/mongo/socket/ocsp_cache.rb +97 -0
- data/lib/mongo/socket/ocsp_verifier.rb +368 -0
- data/lib/mongo/socket/ssl.rb +45 -24
- data/lib/mongo/socket.rb +6 -4
- data/lib/mongo/srv/monitor.rb +7 -13
- data/lib/mongo/srv/resolver.rb +14 -10
- data/lib/mongo/timeout.rb +2 -0
- data/lib/mongo/uri/options_mapper.rb +582 -0
- data/lib/mongo/uri/srv_protocol.rb +3 -2
- data/lib/mongo/uri.rb +21 -390
- data/lib/mongo/utils.rb +12 -1
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo.rb +9 -0
- data/spec/NOTES.aws-auth.md +12 -7
- data/spec/README.md +56 -1
- data/spec/integration/bson_symbol_spec.rb +2 -4
- data/spec/integration/bulk_write_spec.rb +48 -0
- data/spec/integration/client_authentication_options_spec.rb +55 -28
- data/spec/integration/connection_pool_populator_spec.rb +3 -1
- data/spec/integration/cursor_reaping_spec.rb +53 -17
- data/spec/integration/ocsp_connectivity_spec.rb +26 -0
- data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
- data/spec/integration/ocsp_verifier_spec.rb +334 -0
- data/spec/integration/query_cache_spec.rb +1045 -0
- data/spec/integration/query_cache_transactions_spec.rb +179 -0
- data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
- data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -0
- data/spec/integration/sdam_error_handling_spec.rb +69 -18
- data/spec/integration/sdam_events_spec.rb +7 -8
- data/spec/integration/server_selection_spec.rb +36 -0
- data/spec/integration/srv_monitoring_spec.rb +38 -3
- data/spec/integration/srv_spec.rb +56 -0
- data/spec/lite_spec_helper.rb +4 -2
- data/spec/mongo/address_spec.rb +1 -1
- data/spec/mongo/caching_cursor_spec.rb +70 -0
- data/spec/mongo/client_construction_spec.rb +54 -1
- data/spec/mongo/client_encryption_spec.rb +10 -16
- data/spec/mongo/client_spec.rb +40 -0
- data/spec/mongo/cluster/topology/single_spec.rb +14 -5
- data/spec/mongo/cluster_spec.rb +3 -0
- data/spec/mongo/collection/view/explainable_spec.rb +87 -4
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
- data/spec/mongo/collection_spec.rb +60 -0
- data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
- data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
- data/spec/mongo/database_spec.rb +44 -64
- data/spec/mongo/error/no_server_available_spec.rb +1 -1
- data/spec/mongo/index/view_spec.rb +2 -4
- data/spec/mongo/logger_spec.rb +13 -11
- data/spec/mongo/operation/read_preference_legacy_spec.rb +19 -9
- data/spec/mongo/operation/read_preference_op_msg_spec.rb +3 -3
- data/spec/mongo/query_cache_spec.rb +279 -0
- data/spec/mongo/server/app_metadata_shared.rb +7 -33
- data/spec/mongo/server/connection_pool_spec.rb +7 -3
- data/spec/mongo/server/connection_spec.rb +14 -7
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
- data/spec/mongo/socket/ssl_spec.rb +1 -1
- data/spec/mongo/socket_spec.rb +1 -1
- data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
- data/spec/mongo/uri_option_parsing_spec.rb +11 -11
- data/spec/mongo/uri_spec.rb +68 -41
- data/spec/mongo/utils_spec.rb +39 -0
- data/spec/runners/auth.rb +3 -0
- data/spec/runners/connection_string.rb +35 -124
- data/spec/runners/transactions/operation.rb +2 -13
- data/spec/spec_tests/cmap_spec.rb +7 -3
- data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -1
- data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
- data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
- data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
- data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
- data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
- data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
- data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
- data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
- data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
- data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
- data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
- data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
- data/spec/spec_tests/uri_options_spec.rb +31 -33
- data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
- data/spec/support/certificates/atlas-ocsp.crt +41 -0
- data/spec/support/client_registry.rb +4 -8
- data/spec/support/client_registry_macros.rb +4 -4
- data/spec/support/common_shortcuts.rb +45 -0
- data/spec/support/constraints.rb +23 -0
- data/spec/support/lite_constraints.rb +24 -0
- data/spec/support/matchers.rb +16 -0
- data/spec/support/ocsp +1 -0
- data/spec/support/session_registry.rb +52 -0
- data/spec/support/spec_config.rb +22 -12
- data/spec/support/spec_setup.rb +38 -48
- data/spec/support/utils.rb +19 -1
- data.tar.gz.sig +1 -3
- metadata +938 -933
- metadata.gz.sig +0 -0
- data/spec/integration/secondary_reads_spec.rb +0 -102
- data/spec/shared/LICENSE +0 -20
- data/spec/shared/bin/get-mongodb-download-url +0 -17
- data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
- data/spec/shared/lib/mrss/cluster_config.rb +0 -221
- data/spec/shared/lib/mrss/constraints.rb +0 -346
- data/spec/shared/lib/mrss/docker_runner.rb +0 -265
- data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
- data/spec/shared/lib/mrss/server_version_registry.rb +0 -115
- data/spec/shared/lib/mrss/spec_organizer.rb +0 -152
- data/spec/shared/lib/mrss/utils.rb +0 -15
- data/spec/shared/share/Dockerfile.erb +0 -231
- data/spec/shared/shlib/distro.sh +0 -73
- data/spec/shared/shlib/server.sh +0 -290
- data/spec/shared/shlib/set_env.sh +0 -128
@@ -48,6 +48,8 @@ module Mongo
|
|
48
48
|
#
|
49
49
|
# @since 2.0.0
|
50
50
|
def find_one_and_delete(opts = {})
|
51
|
+
QueryCache.clear_namespace(collection.namespace)
|
52
|
+
|
51
53
|
cmd = { :findAndModify => collection.name, :query => filter, :remove => true }
|
52
54
|
cmd[:fields] = projection if projection
|
53
55
|
cmd[:sort] = sort if sort
|
@@ -127,6 +129,8 @@ module Mongo
|
|
127
129
|
#
|
128
130
|
# @since 2.0.0
|
129
131
|
def find_one_and_update(document, opts = {})
|
132
|
+
QueryCache.clear_namespace(collection.namespace)
|
133
|
+
|
130
134
|
cmd = { :findAndModify => collection.name, :query => filter }
|
131
135
|
cmd[:update] = document
|
132
136
|
cmd[:fields] = projection if projection
|
@@ -175,6 +179,8 @@ module Mongo
|
|
175
179
|
#
|
176
180
|
# @since 2.0.0
|
177
181
|
def delete_many(opts = {})
|
182
|
+
QueryCache.clear_namespace(collection.namespace)
|
183
|
+
|
178
184
|
delete_doc = { Operation::Q => filter, Operation::LIMIT => 0 }
|
179
185
|
with_session(opts) do |session|
|
180
186
|
write_concern = if opts[:write_concern]
|
@@ -191,7 +197,7 @@ module Mongo
|
|
191
197
|
:db_name => collection.database.name,
|
192
198
|
:coll_name => collection.name,
|
193
199
|
:write_concern => write_concern,
|
194
|
-
:bypass_document_validation => !!opts[:bypass_document_validation],
|
200
|
+
:bypass_document_validation => !!opts[:bypass_document_validation],
|
195
201
|
:session => session
|
196
202
|
).execute(server, client: client)
|
197
203
|
end
|
@@ -216,6 +222,8 @@ module Mongo
|
|
216
222
|
#
|
217
223
|
# @since 2.0.0
|
218
224
|
def delete_one(opts = {})
|
225
|
+
QueryCache.clear_namespace(collection.namespace)
|
226
|
+
|
219
227
|
delete_doc = { Operation::Q => filter, Operation::LIMIT => 1 }
|
220
228
|
with_session(opts) do |session|
|
221
229
|
write_concern = if opts[:write_concern]
|
@@ -263,6 +271,8 @@ module Mongo
|
|
263
271
|
#
|
264
272
|
# @since 2.0.0
|
265
273
|
def replace_one(replacement, opts = {})
|
274
|
+
QueryCache.clear_namespace(collection.namespace)
|
275
|
+
|
266
276
|
update_doc = { Operation::Q => filter,
|
267
277
|
Operation::U => replacement,
|
268
278
|
}
|
@@ -319,6 +329,8 @@ module Mongo
|
|
319
329
|
#
|
320
330
|
# @since 2.0.0
|
321
331
|
def update_many(spec, opts = {})
|
332
|
+
QueryCache.clear_namespace(collection.namespace)
|
333
|
+
|
322
334
|
update_doc = { Operation::Q => filter,
|
323
335
|
Operation::U => spec,
|
324
336
|
Operation::MULTI => true,
|
@@ -374,6 +386,8 @@ module Mongo
|
|
374
386
|
#
|
375
387
|
# @since 2.0.0
|
376
388
|
def update_one(spec, opts = {})
|
389
|
+
QueryCache.clear_namespace(collection.namespace)
|
390
|
+
|
377
391
|
update_doc = { Operation::Q => filter,
|
378
392
|
Operation::U => spec,
|
379
393
|
}
|
@@ -120,27 +120,31 @@ module Mongo
|
|
120
120
|
# server can write temporary data to disk while executing the find
|
121
121
|
# operation. This option is only available on MongoDB server versions
|
122
122
|
# 4.4 and newer.
|
123
|
-
# @option options
|
124
|
-
#
|
125
|
-
# each response from MongoDB.
|
126
|
-
# @option options :projection [ Hash ] The fields to include or exclude in
|
127
|
-
# returned docs.
|
128
|
-
# @option options :hint [ Hash ] Override default index selection and force
|
129
|
-
# MongoDB to use a specific index for the query.
|
130
|
-
# @option options :limit [ Integer ] Max number of docs to return.
|
131
|
-
# @option options :max_scan [ Integer ] Constrain the query to only scan the
|
132
|
-
# specified number of docs. Use to prevent queries from running too long.
|
133
|
-
# Deprecated as of MongoDB server version 4.0.
|
134
|
-
# @option options :read [ Symbol ] The read preference to use for the query.
|
135
|
-
# If none is provided, the collection's default read preference is used.
|
136
|
-
# @option options :show_disk_loc [ true, false ] Return disk location info as
|
137
|
-
# a field in each doc.
|
138
|
-
# @option options :skip [ Integer ] The number of documents to skip.
|
139
|
-
# @option options :snapshot [ true, false ] Prevents returning a doc more than
|
140
|
-
# once. Deprecated as of MongoDB server version 4.0.
|
141
|
-
# @option options :sort [ Hash ] The key and direction pairs used to sort the
|
142
|
-
# results.
|
123
|
+
# @option options [ Integer ] :batch_size The number of documents to
|
124
|
+
# return in each response from MongoDB.
|
143
125
|
# @option options [ Hash ] :collation The collation to use.
|
126
|
+
# @option options [ String ] :comment Associate a comment with the query.
|
127
|
+
# @option options [ Hash ] :explain Execute an explain with the provided
|
128
|
+
# explain options (known options are :verbose and :verbosity) rather
|
129
|
+
# than a find.
|
130
|
+
# @option options [ Hash ] :hint Override the default index selection and
|
131
|
+
# force MongoDB to use a specific index for the query.
|
132
|
+
# @option options [ Integer ] :limit Max number of documents to return.
|
133
|
+
# @option options [ Integer ] :max_scan Constrain the query to only scan
|
134
|
+
# the specified number of documents. Use to prevent queries from
|
135
|
+
# running for too long. Deprecated as of MongoDB server version 4.0.
|
136
|
+
# @option options [ Hash ] :projection The fields to include or exclude
|
137
|
+
# in the returned documents.
|
138
|
+
# @option options [ Hash ] :read The read preference to use for the
|
139
|
+
# query. If none is provided, the collection's default read preference
|
140
|
+
# is used.
|
141
|
+
# @option options [ true | false ] :show_disk_loc Return disk location
|
142
|
+
# info as a field in each doc.
|
143
|
+
# @option options [ Integer ] :skip The number of documents to skip.
|
144
|
+
# @option options [ true | false ] :snapshot Prevents returning a
|
145
|
+
# document more than once. Deprecated as of MongoDB server version 4.0.
|
146
|
+
# @option options [ Hash ] :sort The key and direction pairs used to sort
|
147
|
+
# the results.
|
144
148
|
#
|
145
149
|
# @since 2.0.0
|
146
150
|
def initialize(collection, filter = {}, options = {})
|
data/lib/mongo/collection.rb
CHANGED
@@ -223,6 +223,7 @@ module Mongo
|
|
223
223
|
# @param [ Hash ] opts The options for the create operation.
|
224
224
|
#
|
225
225
|
# @option options [ Session ] :session The session to use for the operation.
|
226
|
+
# @option opts [ Hash ] :write_concern The write concern options.
|
226
227
|
#
|
227
228
|
# @return [ Result ] The result of the command.
|
228
229
|
#
|
@@ -239,6 +240,11 @@ module Mongo
|
|
239
240
|
operation.delete(:write)
|
240
241
|
operation.delete(:write_concern)
|
241
242
|
client.send(:with_session, opts) do |session|
|
243
|
+
write_concern = if opts[:write_concern]
|
244
|
+
WriteConcern.get(opts[:write_concern])
|
245
|
+
else
|
246
|
+
self.write_concern
|
247
|
+
end
|
242
248
|
server = next_primary(nil, session)
|
243
249
|
if (options[:collation] || options[Operation::COLLATION]) && !server.with_connection { |connection| connection.features }.collation_enabled?
|
244
250
|
raise Error::UnsupportedCollation
|
@@ -264,12 +270,19 @@ module Mongo
|
|
264
270
|
# @param [ Hash ] opts The options for the drop operation.
|
265
271
|
#
|
266
272
|
# @option options [ Session ] :session The session to use for the operation.
|
273
|
+
# @option opts [ Hash ] :write_concern The write concern options.
|
267
274
|
#
|
268
275
|
# @return [ Result ] The result of the command.
|
269
276
|
#
|
270
277
|
# @since 2.0.0
|
271
278
|
def drop(opts = {})
|
272
279
|
client.send(:with_session, opts) do |session|
|
280
|
+
temp_write_concern = write_concern
|
281
|
+
write_concern = if opts[:write_concern]
|
282
|
+
WriteConcern.get(opts[:write_concern])
|
283
|
+
else
|
284
|
+
temp_write_concern
|
285
|
+
end
|
273
286
|
Operation::Drop.new({
|
274
287
|
selector: { :drop => name },
|
275
288
|
db_name: database.name,
|
@@ -543,6 +556,8 @@ module Mongo
|
|
543
556
|
#
|
544
557
|
# @since 2.0.0
|
545
558
|
def insert_one(document, opts = {})
|
559
|
+
QueryCache.clear_namespace(namespace)
|
560
|
+
|
546
561
|
client.send(:with_session, opts) do |session|
|
547
562
|
write_concern = if opts[:write_concern]
|
548
563
|
WriteConcern.get(opts[:write_concern])
|
@@ -573,14 +588,14 @@ module Mongo
|
|
573
588
|
# @param [ Array<Hash> ] documents The documents to insert.
|
574
589
|
# @param [ Hash ] options The insert options.
|
575
590
|
#
|
576
|
-
# @option options [ true | false ] :ordered Whether the operations
|
577
|
-
# should be executed in order.
|
578
591
|
# @option options [ Session ] :session The session to use for the operation.
|
579
592
|
#
|
580
593
|
# @return [ Result ] The database response wrapper.
|
581
594
|
#
|
582
595
|
# @since 2.0.0
|
583
596
|
def insert_many(documents, options = {})
|
597
|
+
QueryCache.clear_namespace(namespace)
|
598
|
+
|
584
599
|
inserts = documents.map{ |doc| { :insert_one => doc }}
|
585
600
|
bulk_write(inserts, options)
|
586
601
|
end
|
@@ -863,5 +878,14 @@ module Mongo
|
|
863
878
|
def namespace
|
864
879
|
"#{database.name}.#{name}"
|
865
880
|
end
|
881
|
+
|
882
|
+
# Whether the collection is a system collection.
|
883
|
+
#
|
884
|
+
# @return [ Boolean ] Whether the system is a system collection.
|
885
|
+
#
|
886
|
+
# @api private
|
887
|
+
def system_collection?
|
888
|
+
name.start_with?('system.')
|
889
|
+
end
|
866
890
|
end
|
867
891
|
end
|
@@ -21,7 +21,7 @@ module Mongo
|
|
21
21
|
# @api private
|
22
22
|
class EncryptionIO
|
23
23
|
|
24
|
-
# Timeout used for
|
24
|
+
# Timeout used for TLS socket connection, reading, and writing.
|
25
25
|
# There is no specific timeout written in the spec. See SPEC-1394
|
26
26
|
# for a discussion and updates on what this timeout should be.
|
27
27
|
SOCKET_TIMEOUT = 10
|
@@ -236,10 +236,10 @@ module Mongo
|
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
239
|
-
# Provide
|
239
|
+
# Provide a TLS socket to be used for KMS calls in a block API
|
240
240
|
#
|
241
|
-
# @param [ String ] endpoint The URI at which to connect the
|
242
|
-
# @yieldparam [ OpenSSL::SSL::SSLSocket ] ssl_socket Yields
|
241
|
+
# @param [ String ] endpoint The URI at which to connect the TLS socket.
|
242
|
+
# @yieldparam [ OpenSSL::SSL::SSLSocket ] ssl_socket Yields a TLS socket
|
243
243
|
# connected to the specified endpoint.
|
244
244
|
#
|
245
245
|
# @raise [ Mongo::Error::KmsError ] If the socket times out or raises
|
@@ -277,7 +277,7 @@ module Mongo
|
|
277
277
|
Timeout.timeout(
|
278
278
|
SOCKET_TIMEOUT,
|
279
279
|
Error::SocketTimeoutError,
|
280
|
-
'KMS
|
280
|
+
'KMS TLS socket close timed out'
|
281
281
|
) do
|
282
282
|
ssl_socket.sysclose
|
283
283
|
end
|
@@ -285,7 +285,7 @@ module Mongo
|
|
285
285
|
end
|
286
286
|
end
|
287
287
|
ensure
|
288
|
-
# Still close tcp socket manually in case
|
288
|
+
# Still close tcp socket manually in case TLS socket creation
|
289
289
|
# fails.
|
290
290
|
begin
|
291
291
|
Timeout.timeout(
|
data/lib/mongo/cursor.rb
CHANGED
@@ -138,6 +138,7 @@ module Mongo
|
|
138
138
|
#
|
139
139
|
# @since 2.0.0
|
140
140
|
def each
|
141
|
+
|
141
142
|
# If we already iterated past the first batch (i.e., called get_more
|
142
143
|
# at least once), the cursor on the server side has advanced past
|
143
144
|
# the first batch and restarting iteration from the beginning by
|
data/lib/mongo/database/view.rb
CHANGED
@@ -100,7 +100,7 @@ module Mongo
|
|
100
100
|
#
|
101
101
|
# @return [ Array<Hash> ] Info for each collection in the database.
|
102
102
|
#
|
103
|
-
# @since 2.0.5
|
103
|
+
# @since 2.0.5
|
104
104
|
def list_collections(options = {})
|
105
105
|
session = client.send(:get_session)
|
106
106
|
collections_info(session, ServerSelector.primary, options)
|
data/lib/mongo/database.rb
CHANGED
@@ -263,6 +263,7 @@ module Mongo
|
|
263
263
|
# @param [ Hash ] options The options for the operation.
|
264
264
|
#
|
265
265
|
# @option options [ Session ] :session The session to use for the operation.
|
266
|
+
# @option opts [ Hash ] :write_concern The write concern options.
|
266
267
|
#
|
267
268
|
# @return [ Result ] The result of the command.
|
268
269
|
#
|
@@ -270,6 +271,11 @@ module Mongo
|
|
270
271
|
def drop(options = {})
|
271
272
|
operation = { :dropDatabase => 1 }
|
272
273
|
client.send(:with_session, options) do |session|
|
274
|
+
write_concern = if options[:write_concern]
|
275
|
+
WriteConcern.get(options[:write_concern])
|
276
|
+
else
|
277
|
+
self.write_concern
|
278
|
+
end
|
273
279
|
Operation::DropDatabase.new({
|
274
280
|
selector: operation,
|
275
281
|
db_name: name,
|
@@ -315,20 +321,8 @@ module Mongo
|
|
315
321
|
|
316
322
|
# Get the Grid "filesystem" for this database.
|
317
323
|
#
|
318
|
-
# @
|
319
|
-
#
|
320
|
-
# @option options [ String ] :bucket_name The prefix for the files and chunks
|
321
|
-
# collections.
|
322
|
-
# @option options [ Integer ] :chunk_size Override the default chunk
|
323
|
-
# size.
|
324
|
-
# @option options [ String ] :fs_name The prefix for the files and chunks
|
325
|
-
# collections.
|
326
|
-
# @option options [ String ] :read The read preference.
|
327
|
-
# @option options [ Session ] :session The session to use.
|
328
|
-
# @option options [ Hash ] :write Deprecated. Equivalent to :write_concern
|
329
|
-
# option.
|
330
|
-
# @option options [ Hash ] :write_concern The write concern options.
|
331
|
-
# Can be :w => Integer|String, :fsync => Boolean, :j => Boolean.
|
324
|
+
# @example Get the GridFS.
|
325
|
+
# database.fs
|
332
326
|
#
|
333
327
|
# @return [ Grid::FSBucket ] The GridFS for the database.
|
334
328
|
#
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2020 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
class Error
|
17
|
+
|
18
|
+
# Raised when an invalid read concern is provided.
|
19
|
+
class InvalidReadConcern < Error
|
20
|
+
# Instantiate the new exception.
|
21
|
+
def initialize(msg = nil)
|
22
|
+
super(msg || 'Invalid read concern option provided.' \
|
23
|
+
'The only valid key is :level, for which accepted values are' \
|
24
|
+
':local, :majority, and :snapshot')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Copyright (C) 2020 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
class Error
|
17
|
+
|
18
|
+
# Server certificate has been revoked (determined via OCSP).
|
19
|
+
class ServerCertificateRevoked < Error
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -17,39 +17,39 @@ module Mongo
|
|
17
17
|
|
18
18
|
# Raised if an unsupported option is specified for an operation.
|
19
19
|
class UnsupportedOption < Error
|
20
|
-
# @api private
|
21
|
-
#
|
22
20
|
# The error message provided when the user passes the hint option to
|
23
21
|
# a write operation against a server that does not support the hint
|
24
22
|
# option and does not provide option validation.
|
23
|
+
#
|
24
|
+
# @api private
|
25
25
|
HINT_MESSAGE = "The MongoDB server handling this request does not support " \
|
26
26
|
"the hint option on this command. The hint option is supported on update " \
|
27
27
|
"commands on MongoDB server versions 4.2 and later and on findAndModify " \
|
28
28
|
"and delete commands on MongoDB server versions 4.4 and later"
|
29
29
|
|
30
|
-
# @api private
|
31
|
-
#
|
32
30
|
# The error message provided when the user passes the hint option to
|
33
31
|
# an unacknowledged write operation.
|
32
|
+
#
|
33
|
+
# @api private
|
34
34
|
UNACKNOWLEDGED_HINT_MESSAGE = "The hint option cannot be specified on " \
|
35
35
|
"an unacknowledged write operation. Remove the hint option or perform " \
|
36
36
|
"this operation with a write concern of at least { w: 1 }"
|
37
37
|
|
38
|
-
# @api private
|
39
|
-
#
|
40
38
|
# The error message provided when the user passes the allow_disk_use
|
41
39
|
# option to a find operation against a server that does not support the
|
42
40
|
# allow_disk_use operation and does not provide option validation.
|
41
|
+
#
|
42
|
+
# @api private
|
43
43
|
ALLOW_DISK_USE_MESSAGE = "The MongoDB server handling this request does " \
|
44
44
|
"not support the allow_disk_use option on this command. The " \
|
45
45
|
"allow_disk_use option is supported on find commands on MongoDB " \
|
46
46
|
"server versions 4.4 and later"
|
47
47
|
|
48
|
-
# @api private
|
49
|
-
#
|
50
48
|
# The error message provided when the user passes the commit_quorum option
|
51
49
|
# to a createIndexes operation against a server that does not support
|
52
50
|
# that option.
|
51
|
+
#
|
52
|
+
# @api private
|
53
53
|
COMMIT_QUORUM_MESSAGE = "The MongoDB server handling this request does " \
|
54
54
|
"not support the commit_quorum option on this command. The commit_quorum " \
|
55
55
|
"option is supported on createIndexes commands on MongoDB server versions " \
|
@@ -57,14 +57,14 @@ module Mongo
|
|
57
57
|
|
58
58
|
# Raise an error about an unsupported hint option.
|
59
59
|
#
|
60
|
-
# @param [ Hash ] options
|
61
|
-
#
|
62
60
|
# @option options [ Boolean ] unacknowledged_write Whether this error
|
63
61
|
# pertains to a hint option passed to an unacknowledged write. Defaults
|
64
62
|
# to false.
|
65
63
|
#
|
66
64
|
# @return [ Mongo::Error::UnsupportedOption ] An error with a default
|
67
65
|
# error message.
|
66
|
+
#
|
67
|
+
# @api private
|
68
68
|
def self.hint_error(**options)
|
69
69
|
unacknowledged_write = options[:unacknowledged_write] || false
|
70
70
|
|
@@ -79,10 +79,10 @@ module Mongo
|
|
79
79
|
|
80
80
|
# Raise an error about an unsupported allow_disk_use option.
|
81
81
|
#
|
82
|
-
# @param [ Hash ] options
|
83
|
-
#
|
84
82
|
# @return [ Mongo::Error::UnsupportedOption ] An error with a default
|
85
83
|
# error message.
|
84
|
+
#
|
85
|
+
# @api private
|
86
86
|
def self.allow_disk_use_error
|
87
87
|
new(ALLOW_DISK_USE_MESSAGE)
|
88
88
|
end
|
@@ -91,6 +91,8 @@ module Mongo
|
|
91
91
|
#
|
92
92
|
# @return [ Mongo::Error::UnsupportedOption ] An error with a default
|
93
93
|
# error message.
|
94
|
+
#
|
95
|
+
# @api private
|
94
96
|
def self.commit_quorum_error
|
95
97
|
new(COMMIT_QUORUM_MESSAGE)
|
96
98
|
end
|
data/lib/mongo/error.rb
CHANGED
@@ -188,6 +188,7 @@ require 'mongo/error/invalid_min_pool_size'
|
|
188
188
|
require 'mongo/error/invalid_read_option'
|
189
189
|
require 'mongo/error/invalid_application_name'
|
190
190
|
require 'mongo/error/invalid_nonce'
|
191
|
+
require 'mongo/error/invalid_read_concern'
|
191
192
|
require 'mongo/error/invalid_replacement_document'
|
192
193
|
require 'mongo/error/invalid_server_auth_response'
|
193
194
|
# Subclass of InvalidServerAuthResponse
|
@@ -215,6 +216,7 @@ require 'mongo/error/session_ended'
|
|
215
216
|
require 'mongo/error/sessions_not_supported'
|
216
217
|
require 'mongo/error/pool_closed_error'
|
217
218
|
require 'mongo/error/raise_original_error'
|
219
|
+
require 'mongo/error/server_certificate_revoked'
|
218
220
|
require 'mongo/error/socket_error'
|
219
221
|
require 'mongo/error/socket_timeout_error'
|
220
222
|
require 'mongo/error/failed_string_prep_validation'
|
data/lib/mongo/grid/fs_bucket.rb
CHANGED
@@ -36,43 +36,6 @@ module Mongo
|
|
36
36
|
# @since 2.1.0
|
37
37
|
FILES_INDEX = { filename: 1, uploadDate: 1 }.freeze
|
38
38
|
|
39
|
-
# Create the GridFS.
|
40
|
-
#
|
41
|
-
# @example Create the GridFS.
|
42
|
-
# Grid::FSBucket.new(database)
|
43
|
-
#
|
44
|
-
# @param [ Database ] database The database the files reside in.
|
45
|
-
# @param [ Hash ] options The GridFS options.
|
46
|
-
#
|
47
|
-
# @option options [ String ] :bucket_name The prefix for the files and chunks
|
48
|
-
# collections.
|
49
|
-
# @option options [ Integer ] :chunk_size Override the default chunk
|
50
|
-
# size.
|
51
|
-
# @option options [ String ] :fs_name The prefix for the files and chunks
|
52
|
-
# collections.
|
53
|
-
# @option options [ String ] :read The read preference.
|
54
|
-
# @option options [ Session ] :session The session to use.
|
55
|
-
# @option options [ Hash ] :write Deprecated. Equivalent to :write_concern
|
56
|
-
# option.
|
57
|
-
# @option options [ Hash ] :write_concern The write concern options.
|
58
|
-
# Can be :w => Integer|String, :fsync => Boolean, :j => Boolean.
|
59
|
-
#
|
60
|
-
# @since 2.0.0
|
61
|
-
def initialize(database, options = {})
|
62
|
-
@database = database
|
63
|
-
@options = options.dup
|
64
|
-
=begin WriteConcern object support
|
65
|
-
if @options[:write_concern].is_a?(WriteConcern::Base)
|
66
|
-
# Cache the instance so that we do not needlessly reconstruct it.
|
67
|
-
@write_concern = @options[:write_concern]
|
68
|
-
@options[:write_concern] = @write_concern.options
|
69
|
-
end
|
70
|
-
=end
|
71
|
-
@options.freeze
|
72
|
-
@chunks_collection = database[chunks_name]
|
73
|
-
@files_collection = database[files_name]
|
74
|
-
end
|
75
|
-
|
76
39
|
# @return [ Collection ] chunks_collection The chunks collection.
|
77
40
|
#
|
78
41
|
# @since 2.0.0
|
@@ -170,6 +133,43 @@ module Mongo
|
|
170
133
|
file.id
|
171
134
|
end
|
172
135
|
|
136
|
+
# Create the GridFS.
|
137
|
+
#
|
138
|
+
# @example Create the GridFS.
|
139
|
+
# Grid::FSBucket.new(database)
|
140
|
+
#
|
141
|
+
# @param [ Database ] database The database the files reside in.
|
142
|
+
# @param [ Hash ] options The GridFS options.
|
143
|
+
#
|
144
|
+
# @option options [ String ] :fs_name The prefix for the files and chunks
|
145
|
+
# collections.
|
146
|
+
# @option options [ String ] :bucket_name The prefix for the files and chunks
|
147
|
+
# collections.
|
148
|
+
# @option options [ Integer ] :chunk_size Override the default chunk
|
149
|
+
# size.
|
150
|
+
# @option options [ String ] :read The read preference.
|
151
|
+
# @option options [ Session ] :session The session to use.
|
152
|
+
# @option options [ Hash ] :write Deprecated. Equivalent to :write_concern
|
153
|
+
# option.
|
154
|
+
# @option options [ Hash ] :write_concern The write concern options.
|
155
|
+
# Can be :w => Integer|String, :fsync => Boolean, :j => Boolean.
|
156
|
+
#
|
157
|
+
# @since 2.0.0
|
158
|
+
def initialize(database, options = {})
|
159
|
+
@database = database
|
160
|
+
@options = options.dup
|
161
|
+
=begin WriteConcern object support
|
162
|
+
if @options[:write_concern].is_a?(WriteConcern::Base)
|
163
|
+
# Cache the instance so that we do not needlessly reconstruct it.
|
164
|
+
@write_concern = @options[:write_concern]
|
165
|
+
@options[:write_concern] = @write_concern.options
|
166
|
+
end
|
167
|
+
=end
|
168
|
+
@options.freeze
|
169
|
+
@chunks_collection = database[chunks_name]
|
170
|
+
@files_collection = database[files_name]
|
171
|
+
end
|
172
|
+
|
173
173
|
# Get the prefix for the GridFS
|
174
174
|
#
|
175
175
|
# @example Get the prefix.
|
data/lib/mongo/lint.rb
CHANGED
@@ -4,12 +4,13 @@ module Mongo
|
|
4
4
|
module Lint
|
5
5
|
|
6
6
|
# Raises LintError if +obj+ is not of type +cls+.
|
7
|
-
|
7
|
+
def assert_type(obj, cls)
|
8
8
|
return unless enabled?
|
9
9
|
unless obj.is_a?(cls)
|
10
10
|
raise Error::LintError, "Expected #{obj} to be a #{cls}"
|
11
11
|
end
|
12
12
|
end
|
13
|
+
module_function :assert_type
|
13
14
|
|
14
15
|
def validate_underscore_read_preference(read_pref)
|
15
16
|
return unless enabled?
|
data/lib/mongo/logger.rb
CHANGED
@@ -21,7 +21,7 @@ module Mongo
|
|
21
21
|
|
22
22
|
class << self
|
23
23
|
|
24
|
-
# Get the wrapped logger. If none was set will return a default
|
24
|
+
# Get the wrapped logger. If none was set will return a default info
|
25
25
|
# level logger.
|
26
26
|
#
|
27
27
|
# @example Get the wrapped logger.
|
@@ -75,8 +75,8 @@ module Mongo
|
|
75
75
|
private
|
76
76
|
|
77
77
|
def default_logger
|
78
|
-
logger = ::Logger.new(
|
79
|
-
logger.level = ::Logger::
|
78
|
+
logger = ::Logger.new(STDOUT)
|
79
|
+
logger.level = ::Logger::INFO
|
80
80
|
logger
|
81
81
|
end
|
82
82
|
end
|
@@ -14,25 +14,24 @@
|
|
14
14
|
|
15
15
|
module Mongo
|
16
16
|
module Operation
|
17
|
-
|
18
|
-
# Aggregate result wrapper.
|
19
|
-
#
|
20
|
-
# @since 2.0.0
|
21
17
|
class Aggregate
|
22
18
|
|
23
19
|
# Defines custom behavior of results in an aggregation context.
|
24
20
|
#
|
25
21
|
# @since 2.0.0
|
22
|
+
# @api semiprivate
|
26
23
|
class Result < Operation::Result
|
27
24
|
|
28
25
|
# The field name for the aggregation explain information.
|
29
26
|
#
|
30
27
|
# @since 2.0.5
|
28
|
+
# @api private
|
31
29
|
EXPLAIN = 'stages'.freeze
|
32
30
|
|
33
31
|
# The legacy field name for the aggregation explain information.
|
34
32
|
#
|
35
33
|
# @since 2.0.5
|
34
|
+
# @api private
|
36
35
|
EXPLAIN_LEGACY = 'serverPipeline'.freeze
|
37
36
|
|
38
37
|
# Get the cursor id for the result.
|
@@ -48,6 +47,7 @@ module Mongo
|
|
48
47
|
# @return [ Integer ] The cursor id.
|
49
48
|
#
|
50
49
|
# @since 2.0.0
|
50
|
+
# @api private
|
51
51
|
def cursor_id
|
52
52
|
cursor_document ? cursor_document[CURSOR_ID] : 0
|
53
53
|
end
|
@@ -62,8 +62,8 @@ module Mongo
|
|
62
62
|
end
|
63
63
|
|
64
64
|
# Get the documents for the aggregation result. This is either the
|
65
|
-
# first document's 'result' field, or if a cursor option was selected,
|
66
|
-
# it is the 'firstBatch' field in the 'cursor' field of the first
|
65
|
+
# first document's 'result' field, or if a cursor option was selected,
|
66
|
+
# it is the 'firstBatch' field in the 'cursor' field of the first
|
67
67
|
# document returned. Otherwise, it is an explain document.
|
68
68
|
#
|
69
69
|
# @example Get the documents.
|
@@ -72,10 +72,11 @@ module Mongo
|
|
72
72
|
# @return [ Array<BSON::Document> ] The documents.
|
73
73
|
#
|
74
74
|
# @since 2.0.0
|
75
|
+
# @api public
|
75
76
|
def documents
|
76
|
-
docs = reply.documents[0][RESULT]
|
77
|
+
docs = reply.documents[0][RESULT]
|
77
78
|
docs ||= cursor_document[FIRST_BATCH] if cursor_document
|
78
|
-
docs ||= explain_document
|
79
|
+
docs ||= explain_document
|
79
80
|
docs
|
80
81
|
end
|
81
82
|
|