mongo 2.13.0 → 2.13.1
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 +0 -0
- data/lib/mongo/client.rb +13 -2
- data/lib/mongo/collection.rb +19 -12
- data/lib/mongo/error/operation_failure.rb +5 -5
- data/lib/mongo/protocol/message.rb +11 -2
- data/lib/mongo/protocol/msg.rb +1 -1
- data/lib/mongo/protocol/query.rb +36 -0
- data/lib/mongo/server/connection_base.rb +3 -5
- data/lib/mongo/version.rb +1 -1
- data/spec/integration/client_authentication_options_spec.rb +37 -0
- data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +6 -2
- data/spec/integration/size_limit_spec.rb +20 -19
- data/spec/mongo/client_construction_spec.rb +11 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd4f9d74906d6f99fd038c0a3b4cfe0ee5cc3a7a4b327debf9c57649112b2cbb
|
4
|
+
data.tar.gz: 052b3f3af1749d9f26d8e3655359650653b4bf71e9198a3d2116afde6d576eb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c016d60512a77572e58ae6553dc9e61ecf6574abc724785858c43987aa84d7b79199589a9be7da702d6385d48f70f65fe135caa36176f9cf6fb638c3e156afc4
|
7
|
+
data.tar.gz: a5c0dbab135a661a3cec5b0eab3300308693474d4c6662b0a18dd33b303f86753390eb0880232794a09ba511824f5d863f7bf428a8af1ca7b7b511458c078049
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mongo/client.rb
CHANGED
@@ -466,7 +466,18 @@ module Mongo
|
|
466
466
|
# construction
|
467
467
|
sdam_proc = options.delete(:sdam_proc)
|
468
468
|
|
469
|
-
|
469
|
+
# For gssapi service_name, the default option is given in a hash
|
470
|
+
# (one level down from the top level).
|
471
|
+
merged_options = default_options(options)
|
472
|
+
options.each do |k, v|
|
473
|
+
default_v = merged_options[k]
|
474
|
+
if Hash === default_v
|
475
|
+
v = default_v.merge(v)
|
476
|
+
end
|
477
|
+
merged_options[k] = v
|
478
|
+
end
|
479
|
+
options = merged_options
|
480
|
+
|
470
481
|
@options = validate_new_options!(options)
|
471
482
|
=begin WriteConcern object support
|
472
483
|
if @options[:write_concern].is_a?(WriteConcern::Base)
|
@@ -632,7 +643,7 @@ module Mongo
|
|
632
643
|
#
|
633
644
|
# @return [ BSON::Document ] The user-defined read preference.
|
634
645
|
# The document may have the following fields:
|
635
|
-
# - *:
|
646
|
+
# - *:mode* -- read preference specified as a symbol; valid values are
|
636
647
|
# *:primary*, *:primary_preferred*, *:secondary*, *:secondary_preferred*
|
637
648
|
# and *:nearest*.
|
638
649
|
# - *:tag_sets* -- an array of hashes.
|
data/lib/mongo/collection.rb
CHANGED
@@ -278,8 +278,12 @@ module Mongo
|
|
278
278
|
}).execute(next_primary(nil, session), client: client)
|
279
279
|
end
|
280
280
|
rescue Error::OperationFailure => ex
|
281
|
-
|
282
|
-
|
281
|
+
# NamespaceNotFound
|
282
|
+
if ex.code == 26 || ex.code.nil? && ex.message =~ /ns not found/
|
283
|
+
false
|
284
|
+
else
|
285
|
+
raise
|
286
|
+
end
|
283
287
|
end
|
284
288
|
|
285
289
|
# Find documents in the collection.
|
@@ -400,7 +404,7 @@ module Mongo
|
|
400
404
|
View::ChangeStream.new(View.new(self, {}, options), pipeline, nil, options)
|
401
405
|
end
|
402
406
|
|
403
|
-
# Gets
|
407
|
+
# Gets an estimated number of matching documents in the collection.
|
404
408
|
#
|
405
409
|
# @example Get the count.
|
406
410
|
# collection.count(name: 1)
|
@@ -429,11 +433,13 @@ module Mongo
|
|
429
433
|
View.new(self, filter || {}, options).count(options)
|
430
434
|
end
|
431
435
|
|
432
|
-
# Gets the number of
|
433
|
-
# method, this will return the exact number of documents matching
|
436
|
+
# Gets the number of documents matching the query. Unlike the deprecated
|
437
|
+
# #count method, this will return the exact number of documents matching
|
438
|
+
# the filter (or exact number of documents in the collection, if no filter
|
439
|
+
# is provided) rather than an estimate.
|
434
440
|
#
|
435
|
-
#
|
436
|
-
#
|
441
|
+
# Use #estimated_document_count to retrieve an estimate of the number
|
442
|
+
# of documents in the collection using the collection metadata.
|
437
443
|
#
|
438
444
|
# @param [ Hash ] filter A filter for matching documents.
|
439
445
|
# @param [ Hash ] options Options for the operation.
|
@@ -454,15 +460,16 @@ module Mongo
|
|
454
460
|
View.new(self, filter, options).count_documents(options)
|
455
461
|
end
|
456
462
|
|
457
|
-
# Gets an estimate of the
|
463
|
+
# Gets an estimate of the number of documents in the collection using the
|
464
|
+
# collection metadata.
|
458
465
|
#
|
459
|
-
#
|
460
|
-
#
|
466
|
+
# Use #count_documents to retrieve the exact number of documents in the
|
467
|
+
# collection, or to count documents matching a filter.
|
461
468
|
#
|
462
469
|
# @param [ Hash ] options Options for the operation.
|
463
470
|
#
|
464
|
-
# @option opts :max_time_ms [ Integer ] The maximum amount of time to allow
|
465
|
-
# run.
|
471
|
+
# @option opts :max_time_ms [ Integer ] The maximum amount of time to allow
|
472
|
+
# the command to run for on the server.
|
466
473
|
# @option opts [ Hash ] :read The read preference options.
|
467
474
|
#
|
468
475
|
# @return [ Integer ] The document count.
|
@@ -97,7 +97,8 @@ module Mongo
|
|
97
97
|
# @since 2.1.1
|
98
98
|
# @deprecated
|
99
99
|
def retryable?
|
100
|
-
write_retryable? ||
|
100
|
+
write_retryable? ||
|
101
|
+
code.nil? && RETRY_MESSAGES.any?{ |m| message.include?(m) }
|
101
102
|
end
|
102
103
|
|
103
104
|
# Whether the error is a retryable error according to the modern retryable
|
@@ -110,11 +111,11 @@ module Mongo
|
|
110
111
|
#
|
111
112
|
# @since 2.4.2
|
112
113
|
def write_retryable?
|
113
|
-
|
114
|
-
|
114
|
+
write_retryable_code? ||
|
115
|
+
code.nil? && WRITE_RETRY_MESSAGES.any? { |m| message.include?(m) }
|
115
116
|
end
|
116
117
|
|
117
|
-
def write_retryable_code?
|
118
|
+
private def write_retryable_code?
|
118
119
|
if code
|
119
120
|
WRITE_RETRY_ERRORS.any? { |e| e[:code] == code }
|
120
121
|
else
|
@@ -122,7 +123,6 @@ module Mongo
|
|
122
123
|
false
|
123
124
|
end
|
124
125
|
end
|
125
|
-
private :write_retryable_code?
|
126
126
|
|
127
127
|
# Error codes and code names that should result in a failing getMore
|
128
128
|
# command on a change stream NOT being resumed.
|
@@ -177,10 +177,19 @@ module Mongo
|
|
177
177
|
#
|
178
178
|
# @param buffer [String] buffer where the message should be inserted
|
179
179
|
# @return [String] buffer containing the serialized message
|
180
|
-
def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil)
|
180
|
+
def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil)
|
181
|
+
max_size =
|
182
|
+
if max_bson_size && bson_overhead
|
183
|
+
max_bson_size + bson_overhead
|
184
|
+
elsif max_bson_size
|
185
|
+
max_bson_size
|
186
|
+
else
|
187
|
+
nil
|
188
|
+
end
|
189
|
+
|
181
190
|
start = buffer.length
|
182
191
|
serialize_header(buffer)
|
183
|
-
serialize_fields(buffer,
|
192
|
+
serialize_fields(buffer, max_size)
|
184
193
|
buffer.replace_int32(start, buffer.length - start)
|
185
194
|
end
|
186
195
|
|
data/lib/mongo/protocol/msg.rb
CHANGED
@@ -146,7 +146,7 @@ module Mongo
|
|
146
146
|
# @return [ BSON::ByteBuffer ] buffer containing the serialized message.
|
147
147
|
#
|
148
148
|
# @since 2.5.0
|
149
|
-
def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil)
|
149
|
+
def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil)
|
150
150
|
validate_document_size!(max_bson_size)
|
151
151
|
|
152
152
|
super
|
data/lib/mongo/protocol/query.rb
CHANGED
@@ -115,12 +115,48 @@ module Mongo
|
|
115
115
|
compress_if_possible(selector.keys.first, compressor, zlib_compression_level)
|
116
116
|
end
|
117
117
|
|
118
|
+
# Serializes message into bytes that can be sent on the wire.
|
119
|
+
#
|
120
|
+
# @param [ BSON::ByteBuffer ] buffer where the message should be inserted.
|
121
|
+
# @param [ Integer ] max_bson_size The maximum bson object size.
|
122
|
+
#
|
123
|
+
# @return [ BSON::ByteBuffer ] buffer containing the serialized message.
|
124
|
+
def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil)
|
125
|
+
validate_document_size!(max_bson_size)
|
126
|
+
|
127
|
+
super
|
128
|
+
end
|
129
|
+
|
118
130
|
protected
|
119
131
|
|
120
132
|
attr_reader :upconverter
|
121
133
|
|
122
134
|
private
|
123
135
|
|
136
|
+
# Validate that the documents in this message are all smaller than the
|
137
|
+
# maxBsonObjectSize. If not, raise an exception.
|
138
|
+
def validate_document_size!(max_bson_size)
|
139
|
+
max_bson_size ||= Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE
|
140
|
+
|
141
|
+
documents = if @selector.key?(:documents)
|
142
|
+
@selector[:documents]
|
143
|
+
elsif @selector.key?(:deletes)
|
144
|
+
@selector[:deletes]
|
145
|
+
elsif @selector.key?(:updates)
|
146
|
+
@selector[:updates]
|
147
|
+
else
|
148
|
+
[]
|
149
|
+
end
|
150
|
+
|
151
|
+
contains_too_large_document = documents.any? do |doc|
|
152
|
+
doc.to_bson.length > max_bson_size
|
153
|
+
end
|
154
|
+
|
155
|
+
if contains_too_large_document
|
156
|
+
raise Error::MaxBSONSize.new('The document exceeds maximum allowed BSON object size after serialization')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
124
160
|
# The operation code required to specify a Query message.
|
125
161
|
# @return [Fixnum] the operation code.
|
126
162
|
#
|
@@ -204,10 +204,8 @@ module Mongo
|
|
204
204
|
if message.bulk_write?
|
205
205
|
# Make the new maximum size equal to the specified reduced size
|
206
206
|
# limit plus the 16KiB overhead allowance.
|
207
|
-
max_bson_size = REDUCED_MAX_BSON_SIZE
|
207
|
+
max_bson_size = REDUCED_MAX_BSON_SIZE
|
208
208
|
end
|
209
|
-
else
|
210
|
-
max_bson_size += MAX_BSON_COMMAND_OVERHEAD
|
211
209
|
end
|
212
210
|
|
213
211
|
# RUBY-2234: It is necessary to check that the message size does not
|
@@ -232,7 +230,7 @@ module Mongo
|
|
232
230
|
# TODO: address the fact that this line mutates the buffer.
|
233
231
|
temp_buffer.put_bytes(buffer.get_bytes(buffer.length))
|
234
232
|
|
235
|
-
message.serialize(temp_buffer, max_bson_size)
|
233
|
+
message.serialize(temp_buffer, max_bson_size, MAX_BSON_COMMAND_OVERHEAD)
|
236
234
|
if temp_buffer.length > max_message_size
|
237
235
|
raise Error::MaxMessageSize.new(max_message_size)
|
238
236
|
end
|
@@ -243,7 +241,7 @@ module Mongo
|
|
243
241
|
# layer should be refactored to allow compression on an already-
|
244
242
|
# serialized message.
|
245
243
|
final_message = message.maybe_compress(compressor, options[:zlib_compression_level])
|
246
|
-
final_message.serialize(buffer, max_bson_size)
|
244
|
+
final_message.serialize(buffer, max_bson_size, MAX_BSON_COMMAND_OVERHEAD)
|
247
245
|
|
248
246
|
buffer
|
249
247
|
end
|
data/lib/mongo/version.rb
CHANGED
@@ -256,6 +256,43 @@ describe 'Client authentication options' do
|
|
256
256
|
expect(client.options[:auth_mech_properties]).to eq({ 'service_name' => 'mongodb' })
|
257
257
|
end
|
258
258
|
end
|
259
|
+
|
260
|
+
context 'when properties are given but not service name' do
|
261
|
+
context 'with URI options' do
|
262
|
+
let(:credentials) { "#{user}:#{pwd}@" }
|
263
|
+
|
264
|
+
context 'with default auth mech properties' do
|
265
|
+
let(:options) { '?authMechanism=GSSAPI&authMechanismProperties=service_realm:foo' }
|
266
|
+
|
267
|
+
it 'sets service name to mongodb' do
|
268
|
+
expect(client.options[:auth_mech_properties]).to eq(
|
269
|
+
'service_name' => 'mongodb',
|
270
|
+
'service_realm' => 'foo',
|
271
|
+
)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context 'with client options' do
|
277
|
+
let(:client_opts) do
|
278
|
+
{
|
279
|
+
auth_mech: :gssapi,
|
280
|
+
user: user,
|
281
|
+
password: pwd,
|
282
|
+
auth_mech_properties: {
|
283
|
+
service_realm: 'foo',
|
284
|
+
}.freeze,
|
285
|
+
}.freeze
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'sets default auth mech properties' do
|
289
|
+
expect(client.options[:auth_mech_properties]).to eq(
|
290
|
+
'service_name' => 'mongodb',
|
291
|
+
'service_realm' => 'foo',
|
292
|
+
)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
259
296
|
end
|
260
297
|
|
261
298
|
context 'with PLAIN auth mechanism' do
|
@@ -162,15 +162,19 @@ describe 'Bulk writes with auto-encryption enabled' do
|
|
162
162
|
context 'when one operation is larger than 16MiB' do
|
163
163
|
let(:requests) do
|
164
164
|
[
|
165
|
-
{ update_one: { filter: { _id: 1 }, update: { ssn: 'a' * (Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE
|
165
|
+
{ update_one: { filter: { _id: 1 }, update: { ssn: 'a' * (Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE) } } },
|
166
166
|
{ update_one: { filter: { _id: 2 }, update: { ssn: 'a' * size_limit } } },
|
167
167
|
]
|
168
168
|
end
|
169
169
|
|
170
|
+
before do
|
171
|
+
expect(requests.first.to_bson.length).to be > Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE
|
172
|
+
end
|
173
|
+
|
170
174
|
it 'raises an exception' do
|
171
175
|
expect do
|
172
176
|
bulk_write.execute
|
173
|
-
end.to raise_error(Mongo::Error::MaxBSONSize, /maximum allowed size
|
177
|
+
end.to raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
|
174
178
|
end
|
175
179
|
end
|
176
180
|
end
|
@@ -62,30 +62,31 @@ describe 'BSON & command size limits' do
|
|
62
62
|
authorized_collection.insert_one(document)
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
it 'fails on the driver when a document larger than 16MiB is inserted' do
|
66
|
+
document = { key: 'a' * (max_document_size - 27), _id: 'foo' }
|
67
|
+
expect(document.to_bson.length).to eq(max_document_size+1)
|
67
68
|
|
68
|
-
|
69
|
-
document
|
70
|
-
|
71
|
-
|
72
|
-
lambda do
|
73
|
-
authorized_collection.insert_one(document)
|
74
|
-
end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
|
75
|
-
end
|
69
|
+
lambda do
|
70
|
+
authorized_collection.insert_one(document)
|
71
|
+
end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
|
76
72
|
end
|
77
73
|
|
78
|
-
|
79
|
-
|
74
|
+
it 'fails on the driver when an update larger than 16MiB is performed' do
|
75
|
+
document = { key: 'a' * (max_document_size - 14) }
|
76
|
+
expect(document.to_bson.length).to eq(max_document_size+1)
|
77
|
+
|
78
|
+
lambda do
|
79
|
+
authorized_collection.update_one({ _id: 'foo' }, document)
|
80
|
+
end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
|
81
|
+
end
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
|
83
|
+
it 'fails on the driver when an delete larger than 16MiB is performed' do
|
84
|
+
document = { key: 'a' * (max_document_size - 14) }
|
85
|
+
expect(document.to_bson.length).to eq(max_document_size+1)
|
84
86
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
87
|
+
lambda do
|
88
|
+
authorized_collection.delete_one(document)
|
89
|
+
end.should raise_error(Mongo::Error::MaxBSONSize, /The document exceeds maximum allowed BSON object size after serialization/)
|
89
90
|
end
|
90
91
|
|
91
92
|
it 'fails in the driver when a document larger than 16MiB+16KiB is inserted' do
|
@@ -2092,6 +2092,7 @@ describe Mongo::Client do
|
|
2092
2092
|
sdam_proc: sdam_proc,
|
2093
2093
|
connect_timeout: 3.08, socket_timeout: 3.09,
|
2094
2094
|
server_selection_timeout: 2.92,
|
2095
|
+
heartbeat_frequency: 100,
|
2095
2096
|
database: SpecConfig.instance.test_db))
|
2096
2097
|
end
|
2097
2098
|
|
@@ -2112,6 +2113,10 @@ describe Mongo::Client do
|
|
2112
2113
|
end
|
2113
2114
|
|
2114
2115
|
it 'does not notify subscribers set up by sdam_proc' do
|
2116
|
+
# On 4.4, the push monitor also is receiving heartbeats.
|
2117
|
+
# Give those some time to be processed.
|
2118
|
+
sleep 2
|
2119
|
+
|
2115
2120
|
expect(subscriber.started_events.length).to be > 0
|
2116
2121
|
subscriber.started_events.clear
|
2117
2122
|
|
@@ -2119,6 +2124,12 @@ describe Mongo::Client do
|
|
2119
2124
|
# subscriber may receive events from the original client.
|
2120
2125
|
|
2121
2126
|
new_client.cluster.next_primary
|
2127
|
+
|
2128
|
+
# Diagnostics
|
2129
|
+
unless subscriber.started_events.empty?
|
2130
|
+
p subscriber.started_events
|
2131
|
+
end
|
2132
|
+
|
2122
2133
|
expect(subscriber.started_events.length).to eq 0
|
2123
2134
|
new_client.cluster.topology.class.should_not be Mongo::Cluster::Topology::Unknown
|
2124
2135
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.13.
|
4
|
+
version: 2.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Brock
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
gpvfPNWMwyBDlHaNS3GfO6cRRxBOvEG05GUCsvtTY4Bpe8yjE64wg1ymb47LMOnv
|
32
32
|
Qb1lGORmf/opg45mluKUYl7pQNZHD0d3
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2020-
|
34
|
+
date: 2020-10-09 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bson
|
metadata.gz.sig
CHANGED
Binary file
|