mongo 2.13.1 → 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.tar.gz.sig +1 -4
- data/lib/mongo.rb +9 -0
- data/lib/mongo/address/ipv4.rb +1 -1
- data/lib/mongo/address/ipv6.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.rb +3 -3
- data/lib/mongo/cluster/topology/single.rb +1 -1
- data/lib/mongo/collection.rb +26 -0
- data/lib/mongo/collection/view.rb +24 -20
- 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/crypt/encryption_io.rb +6 -6
- data/lib/mongo/cursor.rb +1 -0
- data/lib/mongo/database.rb +6 -0
- data/lib/mongo/error.rb +2 -0
- 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/lint.rb +2 -1
- data/lib/mongo/logger.rb +3 -3
- data/lib/mongo/operation.rb +2 -0
- data/lib/mongo/operation/aggregate/result.rb +9 -8
- data/lib/mongo/operation/collections_info/result.rb +2 -0
- 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/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/result/aggregatable.rb +1 -0
- data/lib/mongo/operation/shared/sessions_supported.rb +1 -0
- 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/query_cache.rb +242 -0
- data/lib/mongo/retryable.rb +8 -1
- data/lib/mongo/server.rb +5 -1
- data/lib/mongo/server/connection_common.rb +2 -2
- data/lib/mongo/server/connection_pool.rb +3 -0
- data/lib/mongo/server/monitor.rb +1 -1
- data/lib/mongo/server/monitor/connection.rb +3 -3
- data/lib/mongo/server/pending_connection.rb +2 -2
- data/lib/mongo/server/push_monitor.rb +1 -1
- data/lib/mongo/server_selector/base.rb +5 -1
- data/lib/mongo/session.rb +3 -0
- data/lib/mongo/socket.rb +6 -4
- 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/srv/monitor.rb +7 -13
- data/lib/mongo/srv/resolver.rb +14 -10
- data/lib/mongo/timeout.rb +2 -0
- data/lib/mongo/uri.rb +21 -390
- data/lib/mongo/uri/options_mapper.rb +582 -0
- data/lib/mongo/uri/srv_protocol.rb +3 -2
- data/lib/mongo/utils.rb +12 -1
- data/lib/mongo/version.rb +1 -1
- data/spec/NOTES.aws-auth.md +12 -7
- data/spec/README.md +56 -1
- 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 +68 -0
- 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 +3 -1
- 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_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/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 -0
- data/spec/mongo/error/no_server_available_spec.rb +1 -1
- data/spec/mongo/logger_spec.rb +13 -11
- data/spec/mongo/query_cache_spec.rb +279 -0
- data/spec/mongo/server/connection_pool_spec.rb +7 -3
- data/spec/mongo/server/connection_spec.rb +14 -7
- 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/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_macros.rb +11 -2
- 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 -0
- data/spec/support/utils.rb +19 -1
- metadata +38 -3
- metadata.gz.sig +0 -0
@@ -89,6 +89,16 @@ module Mongo
|
|
89
89
|
self.class.new(view, pipeline, options.merge(explain: true)).first
|
90
90
|
end
|
91
91
|
|
92
|
+
# Whether this aggregation will write its result to a database collection.
|
93
|
+
#
|
94
|
+
# @return [ Boolean ] Whether the aggregation will write its result
|
95
|
+
# to a collection.
|
96
|
+
#
|
97
|
+
# @api private
|
98
|
+
def write?
|
99
|
+
pipeline.any? { |op| op.key?('$out') || op.key?(:$out) || op.key?('$merge') || op.key?(:$merge) }
|
100
|
+
end
|
101
|
+
|
92
102
|
private
|
93
103
|
|
94
104
|
def server_selector
|
@@ -114,10 +124,6 @@ module Mongo
|
|
114
124
|
description.standalone? || description.mongos? || description.primary? || secondary_ok?
|
115
125
|
end
|
116
126
|
|
117
|
-
def write?
|
118
|
-
pipeline.any? { |op| op.key?('$out') || op.key?(:$out) || op.key?('$merge') || op.key?(:$merge) }
|
119
|
-
end
|
120
|
-
|
121
127
|
def secondary_ok?
|
122
128
|
!write?
|
123
129
|
end
|
@@ -136,6 +142,21 @@ module Mongo
|
|
136
142
|
raise Error::UnsupportedCollation.new
|
137
143
|
end
|
138
144
|
end
|
145
|
+
|
146
|
+
# Skip, sort, limit, projection are specified as pipeline stages
|
147
|
+
# rather than as options.
|
148
|
+
def cache_options
|
149
|
+
{
|
150
|
+
namespace: collection.namespace,
|
151
|
+
selector: pipeline,
|
152
|
+
read_concern: view.read_concern,
|
153
|
+
read_preference: view.read_preference,
|
154
|
+
collation: options[:collation],
|
155
|
+
# Aggregations can read documents from more than one collection,
|
156
|
+
# so they will be cleared on every write operation.
|
157
|
+
multi_collection: true,
|
158
|
+
}
|
159
|
+
end
|
139
160
|
end
|
140
161
|
end
|
141
162
|
end
|
@@ -52,21 +52,6 @@ module Mongo
|
|
52
52
|
collation: 'collation'
|
53
53
|
).freeze
|
54
54
|
|
55
|
-
def_delegators :@view, :collection, :database, :filter, :options, :read
|
56
|
-
|
57
|
-
# Get the specification for an explain command that wraps the find
|
58
|
-
# command.
|
59
|
-
#
|
60
|
-
# @example Get the explain spec.
|
61
|
-
# builder.explain_specification
|
62
|
-
#
|
63
|
-
# @return [ Hash ] The specification.
|
64
|
-
#
|
65
|
-
# @since 2.2.0
|
66
|
-
def explain_specification
|
67
|
-
{ selector: { explain: find_command }, db_name: database.name, read: read, session: @session }
|
68
|
-
end
|
69
|
-
|
70
55
|
# Create the find command builder.
|
71
56
|
#
|
72
57
|
# @example Create the find command builder.
|
@@ -81,6 +66,8 @@ module Mongo
|
|
81
66
|
@session = session
|
82
67
|
end
|
83
68
|
|
69
|
+
def_delegators :@view, :collection, :database, :filter, :options, :read
|
70
|
+
|
84
71
|
# Get the specification to pass to the find command operation.
|
85
72
|
#
|
86
73
|
# @example Get the specification.
|
@@ -90,18 +77,51 @@ module Mongo
|
|
90
77
|
#
|
91
78
|
# @since 2.2.0
|
92
79
|
def specification
|
93
|
-
{
|
80
|
+
{
|
81
|
+
selector: find_command,
|
82
|
+
db_name: database.name,
|
83
|
+
read: read,
|
84
|
+
session: @session,
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
# Get the specification for an explain command that wraps the find
|
89
|
+
# command.
|
90
|
+
#
|
91
|
+
# @example Get the explain spec.
|
92
|
+
# builder.explain_specification
|
93
|
+
#
|
94
|
+
# @return [ Hash ] The specification.
|
95
|
+
#
|
96
|
+
# @since 2.2.0
|
97
|
+
def explain_specification
|
98
|
+
{
|
99
|
+
selector: {
|
100
|
+
explain: find_command,
|
101
|
+
},
|
102
|
+
db_name: database.name,
|
103
|
+
read: read,
|
104
|
+
session: @session,
|
105
|
+
# We should always have options{:explain] set if we are explaining.
|
106
|
+
# The explain field is not sent to the server, it will be
|
107
|
+
# processed in the operation layer.
|
108
|
+
explain: options[:explain],
|
109
|
+
}
|
94
110
|
end
|
95
111
|
|
96
112
|
private
|
97
113
|
|
98
114
|
def find_command
|
99
|
-
document = BSON::Document.new(
|
115
|
+
document = BSON::Document.new(
|
116
|
+
find: collection.name,
|
117
|
+
filter: filter,
|
118
|
+
)
|
100
119
|
if collection.read_concern
|
101
120
|
document[:readConcern] = Options::Mapper.transform_values_to_strings(
|
102
121
|
collection.read_concern)
|
103
122
|
end
|
104
|
-
command = Options::Mapper.transform_documents(
|
123
|
+
command = Options::Mapper.transform_documents(
|
124
|
+
convert_flags(options), MAPPINGS, document)
|
105
125
|
if command['oplogReplay']
|
106
126
|
log_warn("oplogReplay is deprecated and ignored by MongoDB 4.4 and later")
|
107
127
|
end
|
@@ -36,16 +36,25 @@ module Mongo
|
|
36
36
|
# @since 2.2.0
|
37
37
|
ALL_PLANS_EXECUTION = 'allPlansExecution'.freeze
|
38
38
|
|
39
|
-
# Get the
|
39
|
+
# Get the query plan for the query.
|
40
40
|
#
|
41
|
-
# @example Get the
|
42
|
-
# view.explain
|
41
|
+
# @example Get the query plan for the query with execution statistics.
|
42
|
+
# view.explain(verbosity: :execution_stats)
|
43
43
|
#
|
44
|
-
# @
|
44
|
+
# @option opts [ true | false ] :verbose The level of detail
|
45
|
+
# to return for MongoDB 2.6 servers.
|
46
|
+
# @option opts [ String | Symbol ] :verbosity The type of information
|
47
|
+
# to return for MongoDB 3.0 and newer servers. If the value is a
|
48
|
+
# symbol, it will be stringified and converted from underscore
|
49
|
+
# style to camel case style (e.g. :query_planner => "queryPlanner").
|
50
|
+
#
|
51
|
+
# @return [ Hash ] A single document with the query plan.
|
52
|
+
#
|
53
|
+
# @see https://docs.mongodb.com/manual/reference/method/db.collection.explain/#db.collection.explain
|
45
54
|
#
|
46
55
|
# @since 2.0.0
|
47
|
-
def explain
|
48
|
-
self.class.new(collection, selector, options.merge(explain_options)).first
|
56
|
+
def explain(**opts)
|
57
|
+
self.class.new(collection, selector, options.merge(explain_options(**opts))).first
|
49
58
|
end
|
50
59
|
|
51
60
|
private
|
@@ -54,9 +63,19 @@ module Mongo
|
|
54
63
|
!!options[:explain]
|
55
64
|
end
|
56
65
|
|
57
|
-
|
66
|
+
# @option opts [ true | false ] :verbose The level of detail
|
67
|
+
# to return for MongoDB 2.6 servers.
|
68
|
+
# @option opts [ String | Symbol ] :verbosity The type of information
|
69
|
+
# to return for MongoDB 3.0 and newer servers. If the value is a
|
70
|
+
# symbol, it will be stringified and converted from underscore
|
71
|
+
# style to camel case style (e.g. :query_planner => "queryPlanner").
|
72
|
+
def explain_options(**opts)
|
58
73
|
explain_limit = limit || 0
|
59
|
-
|
74
|
+
# Note: opts will never be nil here.
|
75
|
+
if Symbol === opts[:verbosity]
|
76
|
+
opts[:verbosity] = Utils.camelize(opts[:verbosity])
|
77
|
+
end
|
78
|
+
{ limit: -explain_limit.abs, explain: opts }
|
60
79
|
end
|
61
80
|
end
|
62
81
|
end
|
@@ -35,19 +35,34 @@ module Mongo
|
|
35
35
|
#
|
36
36
|
# @yieldparam [ Hash ] Each matching document.
|
37
37
|
def each
|
38
|
-
@cursor =
|
39
|
-
|
40
|
-
@cursor = if respond_to?(:write?, true) && write?
|
41
|
-
server = server_selector.select_server(cluster, nil, session)
|
42
|
-
result = send_initial_query(server, session)
|
43
|
-
Cursor.new(view, result, server, session: session)
|
38
|
+
@cursor = if use_query_cache? && cached_cursor
|
39
|
+
cached_cursor
|
44
40
|
else
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
session = client.send(:get_session, @options)
|
42
|
+
select_cursor(session)
|
43
|
+
end
|
44
|
+
|
45
|
+
if use_query_cache?
|
46
|
+
# No need to store the cursor in the query cache if there is
|
47
|
+
# already a cached cursor stored at this key.
|
48
|
+
QueryCache.set(@cursor, **cache_options) unless cached_cursor
|
49
|
+
|
50
|
+
# If a query with a limit is performed, the query cache will
|
51
|
+
# re-use results from an earlier query with the same or larger
|
52
|
+
# limit, and then impose the lower limit during iteration.
|
53
|
+
limit_for_cached_query = respond_to?(:limit) ? limit : nil
|
48
54
|
end
|
55
|
+
|
49
56
|
if block_given?
|
50
|
-
|
57
|
+
# Ruby versions 2.5 and older do not support arr[0..nil] syntax, so
|
58
|
+
# this must be a separate conditional.
|
59
|
+
cursor_to_iterate = if limit_for_cached_query
|
60
|
+
@cursor.to_a[0...limit_for_cached_query]
|
61
|
+
else
|
62
|
+
@cursor
|
63
|
+
end
|
64
|
+
|
65
|
+
cursor_to_iterate.each do |doc|
|
51
66
|
yield doc
|
52
67
|
end
|
53
68
|
else
|
@@ -77,6 +92,46 @@ module Mongo
|
|
77
92
|
|
78
93
|
private
|
79
94
|
|
95
|
+
def select_cursor(session)
|
96
|
+
if respond_to?(:write?, true) && write?
|
97
|
+
server = server_selector.select_server(cluster, nil, session)
|
98
|
+
result = send_initial_query(server, session)
|
99
|
+
|
100
|
+
# RUBY-2367: This will be updated to allow the query cache to
|
101
|
+
# cache cursors with multi-batch results.
|
102
|
+
if use_query_cache?
|
103
|
+
CachingCursor.new(view, result, server, session: session)
|
104
|
+
else
|
105
|
+
Cursor.new(view, result, server, session: session)
|
106
|
+
end
|
107
|
+
else
|
108
|
+
read_with_retry_cursor(session, server_selector, view) do |server|
|
109
|
+
send_initial_query(server, session)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def cached_cursor
|
115
|
+
QueryCache.get(**cache_options)
|
116
|
+
end
|
117
|
+
|
118
|
+
def cache_options
|
119
|
+
# NB: this hash is passed as keyword argument and must have symbol
|
120
|
+
# keys.
|
121
|
+
{
|
122
|
+
namespace: collection.namespace,
|
123
|
+
selector: selector,
|
124
|
+
skip: skip,
|
125
|
+
sort: sort,
|
126
|
+
limit: limit,
|
127
|
+
projection: projection,
|
128
|
+
collation: collation,
|
129
|
+
read_concern: read_concern,
|
130
|
+
read_preference: read_preference
|
131
|
+
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
80
135
|
def initial_query_op(server, session)
|
81
136
|
if server.with_connection { |connection| connection.features }.find_command_enabled?
|
82
137
|
initial_command_op(session)
|
@@ -92,10 +147,11 @@ module Mongo
|
|
92
147
|
end
|
93
148
|
|
94
149
|
def initial_command_op(session)
|
150
|
+
builder = Builder::FindCommand.new(self, session)
|
95
151
|
if explained?
|
96
|
-
Operation::Explain.new(
|
152
|
+
Operation::Explain.new(builder.explain_specification)
|
97
153
|
else
|
98
|
-
Operation::Find.new(
|
154
|
+
Operation::Find.new(builder.specification)
|
99
155
|
end
|
100
156
|
end
|
101
157
|
|
@@ -103,6 +159,10 @@ module Mongo
|
|
103
159
|
validate_collation!(server, collation)
|
104
160
|
initial_query_op(server, session).execute(server, client: client)
|
105
161
|
end
|
162
|
+
|
163
|
+
def use_query_cache?
|
164
|
+
QueryCache.enabled? && !collection.system_collection?
|
165
|
+
end
|
106
166
|
end
|
107
167
|
end
|
108
168
|
end
|
@@ -45,7 +45,17 @@ module Mongo
|
|
45
45
|
#
|
46
46
|
# @since 2.0.0
|
47
47
|
def aggregate(pipeline, options = {})
|
48
|
-
Aggregation.new(self, pipeline, options)
|
48
|
+
aggregation = Aggregation.new(self, pipeline, options)
|
49
|
+
|
50
|
+
# Because the $merge and $out pipeline stages write documents to the
|
51
|
+
# collection, it is necessary to clear the cache when they are performed.
|
52
|
+
#
|
53
|
+
# Opt to clear the entire cache rather than one namespace because
|
54
|
+
# the $out and $merge stages do not have to write to the same namespace
|
55
|
+
# on which the aggregation is performed.
|
56
|
+
QueryCache.clear if aggregation.write?
|
57
|
+
|
58
|
+
aggregation
|
49
59
|
end
|
50
60
|
|
51
61
|
# Allows the server to write temporary data to disk while executing
|
@@ -90,7 +100,7 @@ module Mongo
|
|
90
100
|
# @param [ Integer ] batch_size The size of each batch of results.
|
91
101
|
#
|
92
102
|
# @return [ Integer, View ] Either the batch_size value or a
|
93
|
-
#
|
103
|
+
# new +View+.
|
94
104
|
#
|
95
105
|
# @since 2.0.0
|
96
106
|
def batch_size(batch_size = nil)
|
@@ -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
|
}
|
@@ -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
|