mongo 2.4.0.rc0 → 2.4.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 -2
- data/lib/mongo/bulk_write/validatable.rb +3 -1
- data/lib/mongo/client.rb +30 -3
- data/lib/mongo/cluster/app_metadata.rb +7 -2
- data/lib/mongo/collection.rb +3 -1
- data/lib/mongo/collection/view.rb +3 -1
- data/lib/mongo/collection/view/aggregation.rb +3 -1
- data/lib/mongo/collection/view/builder/find_command.rb +20 -5
- data/lib/mongo/collection/view/map_reduce.rb +3 -1
- data/lib/mongo/collection/view/writable.rb +12 -2
- data/lib/mongo/cursor/builder/get_more_command.rb +3 -2
- data/lib/mongo/error/closed_stream.rb +1 -1
- data/lib/mongo/error/invalid_server_preference.rb +1 -1
- data/lib/mongo/index/view.rb +3 -1
- data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
- data/lib/mongo/operation/write/create_index.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +1 -1
- data/lib/mongo/operation/write/update.rb +1 -1
- data/lib/mongo/protocol/delete.rb +4 -1
- data/lib/mongo/protocol/get_more.rb +4 -1
- data/lib/mongo/protocol/insert.rb +7 -3
- data/lib/mongo/protocol/kill_cursors.rb +4 -1
- data/lib/mongo/protocol/message.rb +5 -1
- data/lib/mongo/protocol/query.rb +11 -4
- data/lib/mongo/protocol/update.rb +4 -1
- data/lib/mongo/server/connectable.rb +8 -2
- data/lib/mongo/server/connection_pool.rb +3 -1
- data/lib/mongo/server/monitor.rb +1 -0
- data/lib/mongo/socket.rb +16 -8
- data/lib/mongo/socket/ssl.rb +24 -9
- data/lib/mongo/uri.rb +6 -6
- data/lib/mongo/version.rb +1 -1
- data/mongo.gemspec +1 -1
- data/spec/mongo/bulk_write_spec.rb +117 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +26 -0
- data/spec/mongo/collection/view/builder/find_command_spec.rb +244 -2
- data/spec/mongo/collection/view/map_reduce_spec.rb +13 -0
- data/spec/mongo/collection/view/readable_spec.rb +26 -0
- data/spec/mongo/collection/view/writable_spec.rb +104 -0
- data/spec/mongo/collection/view_spec.rb +13 -0
- data/spec/mongo/collection_spec.rb +226 -7
- data/spec/mongo/crud_spec.rb +5 -5
- data/spec/mongo/index/view_spec.rb +53 -0
- data/spec/mongo/server/connection_spec.rb +45 -26
- data/spec/mongo/socket/ssl_spec.rb +358 -22
- data/spec/spec_helper.rb +4 -0
- data/spec/support/authorization.rb +3 -3
- data/spec/support/certificates/client_cert.pem +21 -0
- data/spec/support/certificates/client_key.pem +28 -0
- data/spec/support/certificates/client_key_encrypted.pem +30 -0
- data/spec/support/crud.rb +67 -22
- data/spec/support/crud/read.rb +18 -36
- data/spec/support/crud/write.rb +0 -44
- data/spec/support/crud_tests/read/aggregate-collation.yml +17 -0
- data/spec/support/crud_tests/read/aggregate-out.yml +28 -0
- data/spec/support/crud_tests/read/aggregate.yml +1 -35
- data/spec/support/crud_tests/read/count-collation.yml +15 -0
- data/spec/support/crud_tests/read/count.yml +3 -15
- data/spec/support/crud_tests/read/distinct-collation.yml +17 -0
- data/spec/support/crud_tests/read/distinct.yml +1 -14
- data/spec/support/crud_tests/read/find-collation.yml +15 -0
- data/spec/support/crud_tests/read/find.yml +1 -12
- data/spec/support/crud_tests/write/deleteMany-collation.yml +22 -0
- data/spec/support/crud_tests/write/deleteMany.yml +1 -23
- data/spec/support/crud_tests/write/deleteOne-collation.yml +22 -0
- data/spec/support/crud_tests/write/deleteOne.yml +1 -21
- data/spec/support/crud_tests/write/findOneAndDelete-collation.yml +23 -0
- data/spec/support/crud_tests/write/findOneAndDelete.yml +2 -28
- data/spec/support/crud_tests/write/findOneAndReplace-collation.yml +24 -0
- data/spec/support/crud_tests/write/findOneAndReplace-upsert.yml +47 -0
- data/spec/support/crud_tests/write/findOneAndReplace.yml +13 -53
- data/spec/support/crud_tests/write/findOneAndUpdate-collation.yml +27 -0
- data/spec/support/crud_tests/write/findOneAndUpdate.yml +8 -51
- data/spec/support/crud_tests/write/insertMany.yml +1 -2
- data/spec/support/crud_tests/write/insertOne.yml +1 -2
- data/spec/support/crud_tests/write/replaceOne-collation.yml +23 -0
- data/spec/support/crud_tests/write/replaceOne-upsert.yml +48 -0
- data/spec/support/crud_tests/write/replaceOne.yml +11 -45
- data/spec/support/crud_tests/write/updateMany-collation.yml +27 -0
- data/spec/support/crud_tests/write/updateMany.yml +10 -42
- data/spec/support/crud_tests/write/updateOne-collation.yml +24 -0
- data/spec/support/crud_tests/write/updateOne.yml +7 -33
- data/spec/support/sdam/rs/new_primary_new_setversion.yml +1 -1
- data/spec/support/sdam/rs/null_election_id.yml +1 -0
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +2 -3
- data/spec/support/sdam/rs/primary_disconnect_setversion.yml +1 -2
- data/spec/support/sdam/single/direct_connection_rsarbiter.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rsprimary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rssecondary.yml +1 -1
- metadata +40 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fceb612725957e97b29a1b35a376821d685dea7
|
4
|
+
data.tar.gz: 3f1ee5867327a164aa2bff5e00a517387df406e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70a87aadb4c5f8a31582dfada8c8810a4a71d8c7b59fd4fda010f2d680a8d555a2401e190e37d37106f268d40019e67926a7cb48ae33f5937d90b5227e9b29af
|
7
|
+
data.tar.gz: c6d42e01149a0140f59494999d98e69a3f7df8480fc5fac6054d518fca9d80fa58278e3529a8b9e7274ef069080d4e5f07cf1aae72e3119c90527465268b01b1
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
"d��
|
2
|
-
�=.WX��E�:J4z�bc�x\=��jp)��y�s���ڬW)e �|wBos�ͬ���G-Xx��AOfj�`巪Z�`���z{���Wl�P"��J���͏˷P�HHO�2��ftz�h��,g�\hc
|
1
|
+
,��J�|)�@��0�Lzu�](�dAC���y��Cϭ�"d��qg�)�/���ً*5��;H{U|�\�7�$P��s0��������d{�d{x���M�>��RT/I��c�B�ǵ��e��I�A� ��3Mk�p�e�� ��}l���p�������O�Ȭ:��q�Z�0��7^D��ZrȦZq�=������S�����cB�,��<Q��^���UFhHF�Bf�ݩ�L{Ʃ-qQQ���m �+�]
|
@@ -40,7 +40,9 @@ module Mongo
|
|
40
40
|
def validate(name, document)
|
41
41
|
validate_operation(name)
|
42
42
|
validate_document(name, document)
|
43
|
-
|
43
|
+
if document.respond_to?(:keys) && (document[:collation] || document[Operation::COLLATION])
|
44
|
+
@has_collation = true
|
45
|
+
end
|
44
46
|
end
|
45
47
|
|
46
48
|
private
|
data/lib/mongo/client.rb
CHANGED
@@ -55,8 +55,14 @@ module Mongo
|
|
55
55
|
:socket_timeout,
|
56
56
|
:ssl,
|
57
57
|
:ssl_ca_cert,
|
58
|
+
:ssl_ca_cert_string,
|
59
|
+
:ssl_ca_cert_object,
|
58
60
|
:ssl_cert,
|
61
|
+
:ssl_cert_string,
|
62
|
+
:ssl_cert_object,
|
59
63
|
:ssl_key,
|
64
|
+
:ssk_key_string,
|
65
|
+
:ssl_key_object,
|
60
66
|
:ssl_key_pass_phrase,
|
61
67
|
:ssl_verify,
|
62
68
|
:truncate_logs,
|
@@ -167,16 +173,37 @@ module Mongo
|
|
167
173
|
# connect to. Servers not in this replica set will be ignored.
|
168
174
|
# @option options [ true, false ] :ssl Whether to use SSL.
|
169
175
|
# @option options [ String ] :ssl_cert The certificate file used to identify
|
170
|
-
# the connection against MongoDB.
|
176
|
+
# the connection against MongoDB. This option, if present, takes precedence
|
177
|
+
# over the values of :ssl_cert_string and :ssl_cert_object
|
178
|
+
# @option options [ String ] :ssl_cert_string A string containing the PEM-encoded
|
179
|
+
# certificate used to identify the connection against MongoDB. This option, if present,
|
180
|
+
# takes precedence over the value of :ssl_cert_object
|
181
|
+
# @option options [ OpenSSL::X509::Certificate ] :ssl_cert_object The OpenSSL::X509::Certificate
|
182
|
+
# used to identify the connection against MongoDB
|
171
183
|
# @option options [ String ] :ssl_key The private keyfile used to identify the
|
172
184
|
# connection against MongoDB. Note that even if the key is stored in the same
|
173
|
-
# file as the certificate, both need to be explicitly specified.
|
185
|
+
# file as the certificate, both need to be explicitly specified. This option,
|
186
|
+
# if present, takes precedence over the values of :ssl_key_string and :ssl_key_object
|
187
|
+
# @option options [ String ] :ssl_key_string A string containing the PEM-encoded private key
|
188
|
+
# used to identify the connection against MongoDB. This parameter, if present,
|
189
|
+
# takes precedence over the value of option :ssl_key_object
|
190
|
+
# @option options [ OpenSSL::PKey ] :ssl_key_object The private key used to identify the
|
191
|
+
# connection against MongoDB
|
174
192
|
# @option options [ String ] :ssl_key_pass_phrase A passphrase for the private key.
|
175
193
|
# @option options [ true, false ] :ssl_verify Whether or not to do peer certification
|
176
194
|
# validation.
|
177
195
|
# @option options [ String ] :ssl_ca_cert The file containing a set of concatenated
|
178
196
|
# certification authority certifications used to validate certs passed from the
|
179
|
-
# other end of the connection.
|
197
|
+
# other end of the connection. One of :ssl_ca_cert, :ssl_ca_cert_string or
|
198
|
+
# :ssl_ca_cert_object (in order of priority) is required for :ssl_verify.
|
199
|
+
# @option options [ String ] :ssl_ca_cert_string A string containing a set of concatenated
|
200
|
+
# certification authority certifications used to validate certs passed from the
|
201
|
+
# other end of the connection. One of :ssl_ca_cert, :ssl_ca_cert_string or
|
202
|
+
# :ssl_ca_cert_object (in order of priority) is required for :ssl_verify.
|
203
|
+
# @option options [ Array<OpenSSL::X509::Certificate> ] :ssl_ca_cert_object An array of OpenSSL::X509::Certificate
|
204
|
+
# reprenting the certification authority certifications used to validate certs passed from the
|
205
|
+
# other end of the connection. One of :ssl_ca_cert, :ssl_ca_cert_string or
|
206
|
+
# :ssl_ca_cert_object (in order of priority) is required for :ssl_verify.
|
180
207
|
# @option options [ Float ] :socket_timeout The timeout, in seconds, to
|
181
208
|
# execute operations on a socket.
|
182
209
|
# @option options [ String ] :user The user name.
|
@@ -36,6 +36,11 @@ module Mongo
|
|
36
36
|
# @ since 2.4.0
|
37
37
|
MAX_APP_NAME_SIZE = 128.freeze
|
38
38
|
|
39
|
+
# The driver name.
|
40
|
+
#
|
41
|
+
# @ since 2.4.0
|
42
|
+
DRIVER_NAME = 'mongo-ruby-driver'
|
43
|
+
|
39
44
|
# Instantiate the new AppMetadata object.
|
40
45
|
#
|
41
46
|
# @api private
|
@@ -101,7 +106,7 @@ module Mongo
|
|
101
106
|
|
102
107
|
def driver_doc
|
103
108
|
{
|
104
|
-
name:
|
109
|
+
name: DRIVER_NAME,
|
105
110
|
version: Mongo::VERSION
|
106
111
|
}
|
107
112
|
end
|
@@ -116,7 +121,7 @@ module Mongo
|
|
116
121
|
|
117
122
|
def type
|
118
123
|
(RbConfig::CONFIG && RbConfig::CONFIG['host_os']) ?
|
119
|
-
RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase
|
124
|
+
RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase : 'unknown'
|
120
125
|
end
|
121
126
|
|
122
127
|
def name
|
data/lib/mongo/collection.rb
CHANGED
@@ -172,7 +172,9 @@ module Mongo
|
|
172
172
|
operation = { :create => name }.merge(options)
|
173
173
|
operation.delete(:write)
|
174
174
|
server = next_primary
|
175
|
-
|
175
|
+
if (options[:collation] || options[Operation::COLLATION]) && !server.features.collation_enabled?
|
176
|
+
raise Error::UnsupportedCollation.new
|
177
|
+
end
|
176
178
|
Operation::Commands::Create.new({
|
177
179
|
selector: operation,
|
178
180
|
db_name: database.name,
|
@@ -178,7 +178,9 @@ module Mongo
|
|
178
178
|
end
|
179
179
|
|
180
180
|
def validate_collation!(server, opts)
|
181
|
-
|
181
|
+
if (opts[:collation] || opts[Operation::COLLATION]) && !server.features.collation_enabled?
|
182
|
+
raise Error::UnsupportedCollation.new
|
183
|
+
end
|
182
184
|
end
|
183
185
|
|
184
186
|
def view; self; end
|
@@ -120,7 +120,9 @@ module Mongo
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def validate_collation!(server)
|
123
|
-
|
123
|
+
if (@options[:collation] || @options[Operation::COLLATION]) && !server.features.collation_enabled?
|
124
|
+
raise Error::UnsupportedCollation.new
|
125
|
+
end
|
124
126
|
end
|
125
127
|
end
|
126
128
|
end
|
@@ -96,15 +96,30 @@ module Mongo
|
|
96
96
|
def find_command
|
97
97
|
document = BSON::Document.new('find' => collection.name, 'filter' => filter)
|
98
98
|
command = Options::Mapper.transform_documents(convert_flags(options), MAPPINGS, document)
|
99
|
-
|
99
|
+
convert_limit_and_batch_size(command)
|
100
|
+
command
|
100
101
|
end
|
101
102
|
|
102
|
-
def
|
103
|
-
if command[:limit] && command[:limit] < 0
|
104
|
-
|
103
|
+
def convert_limit_and_batch_size(command)
|
104
|
+
if command[:limit] && command[:limit] < 0 &&
|
105
|
+
command[:batchSize] && command[:batchSize] < 0
|
106
|
+
|
107
|
+
command[:limit] = command[:limit].abs
|
108
|
+
command[:batchSize] = command[:limit].abs
|
105
109
|
command[:singleBatch] = true
|
110
|
+
|
111
|
+
else
|
112
|
+
[:limit, :batchSize].each do |opt|
|
113
|
+
if command[opt]
|
114
|
+
if command[opt] < 0
|
115
|
+
command[opt] = command[opt].abs
|
116
|
+
command[:singleBatch] = true
|
117
|
+
elsif command[opt] == 0
|
118
|
+
command.delete(opt)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
106
122
|
end
|
107
|
-
command
|
108
123
|
end
|
109
124
|
|
110
125
|
def convert_flags(options)
|
@@ -237,7 +237,9 @@ module Mongo
|
|
237
237
|
end
|
238
238
|
|
239
239
|
def validate_collation!(server)
|
240
|
-
|
240
|
+
if (options[:collation] || options[Operation::COLLATION]) && !server.features.collation_enabled?
|
241
|
+
raise Error::UnsupportedCollation.new
|
242
|
+
end
|
241
243
|
end
|
242
244
|
end
|
243
245
|
end
|
@@ -211,7 +211,12 @@ module Mongo
|
|
211
211
|
server = next_primary
|
212
212
|
validate_collation!(server, opts)
|
213
213
|
delete_doc = { Operation::Q => filter, Operation::LIMIT => value }
|
214
|
-
|
214
|
+
# We must extract the collation at the String key as well so that if w == 0,
|
215
|
+
# an error can be raised later when an OpCode is used.
|
216
|
+
# Otherwise, the collation will silently not be sent.
|
217
|
+
if collation = opts[:collation] || opts[Operation::COLLATION]
|
218
|
+
delete_doc[:collation] = collation
|
219
|
+
end
|
215
220
|
write_with_retry do
|
216
221
|
Operation::Write::Delete.new(
|
217
222
|
:delete => delete_doc,
|
@@ -229,7 +234,12 @@ module Mongo
|
|
229
234
|
Operation::U => spec,
|
230
235
|
Operation::MULTI => multi,
|
231
236
|
Operation::UPSERT => !!opts[:upsert] }
|
232
|
-
|
237
|
+
# We must extract the collation at the String key as well so that if w == 0,
|
238
|
+
# an error can be raised later when an OpCode is used.
|
239
|
+
# Otherwise, the collation will silently not be sent.
|
240
|
+
if collation = opts[:collation] || opts[Operation::COLLATION]
|
241
|
+
update_doc[:collation] = collation
|
242
|
+
end
|
233
243
|
write_with_retry do
|
234
244
|
Operation::Write::Update.new(
|
235
245
|
:update => update_doc,
|
@@ -25,7 +25,8 @@ module Mongo
|
|
25
25
|
# @return [ Cursor ] cursor The cursor.
|
26
26
|
attr_reader :cursor
|
27
27
|
|
28
|
-
def_delegators :@cursor, :
|
28
|
+
def_delegators :@cursor, :collection_name, :database, :view
|
29
|
+
def_delegators :view, :batch_size
|
29
30
|
|
30
31
|
# Create the new builder.
|
31
32
|
#
|
@@ -55,7 +56,7 @@ module Mongo
|
|
55
56
|
|
56
57
|
def get_more_command
|
57
58
|
command = { :getMore => cursor.id, :collection => collection_name }
|
58
|
-
command[:batchSize] = batch_size if batch_size
|
59
|
+
command[:batchSize] = batch_size.abs if batch_size && batch_size != 0
|
59
60
|
# If the max_await_time_ms option is set, then we set maxTimeMS on
|
60
61
|
# the get more command.
|
61
62
|
if view.respond_to?(:max_await_time_ms)
|
data/lib/mongo/index/view.rb
CHANGED
@@ -271,7 +271,9 @@ module Mongo
|
|
271
271
|
end
|
272
272
|
|
273
273
|
def validate_collation!(model, server)
|
274
|
-
|
274
|
+
if (model[:collation] || model[Operation::COLLATION]) && !server.features.collation_enabled?
|
275
|
+
raise Error::UnsupportedCollation.new
|
276
|
+
end
|
275
277
|
end
|
276
278
|
end
|
277
279
|
end
|
@@ -55,7 +55,7 @@ module Mongo
|
|
55
55
|
#
|
56
56
|
# @since 2.0.0
|
57
57
|
def aggregate_write_concern_errors(count)
|
58
|
-
@replies.each_with_index.reduce(nil) do |errors, (reply,
|
58
|
+
@replies.each_with_index.reduce(nil) do |errors, (reply, _)|
|
59
59
|
if write_concern_errors = reply.documents.first[Error::WRITE_CONCERN_ERRORS]
|
60
60
|
(errors || []) << write_concern_errors.reduce(nil) do |errs, wce|
|
61
61
|
wce.merge!('index' => count + wce['index'])
|
@@ -46,6 +46,7 @@ module Mongo
|
|
46
46
|
@selector = selector
|
47
47
|
@flags = options[:flags] || []
|
48
48
|
@upconverter = Upconverter.new(collection, selector, options)
|
49
|
+
super
|
49
50
|
end
|
50
51
|
|
51
52
|
# Return the event payload for monitoring.
|
@@ -65,10 +66,12 @@ module Mongo
|
|
65
66
|
}
|
66
67
|
end
|
67
68
|
|
68
|
-
|
69
|
+
protected
|
69
70
|
|
70
71
|
attr_reader :upconverter
|
71
72
|
|
73
|
+
private
|
74
|
+
|
72
75
|
# The operation code required to specify a Delete message.
|
73
76
|
# @return [Fixnum] the operation code.
|
74
77
|
def op_code
|
@@ -42,6 +42,7 @@ module Mongo
|
|
42
42
|
@number_to_return = number_to_return
|
43
43
|
@cursor_id = cursor_id
|
44
44
|
@upconverter = Upconverter.new(collection, cursor_id, number_to_return)
|
45
|
+
super
|
45
46
|
end
|
46
47
|
|
47
48
|
# Return the event payload for monitoring.
|
@@ -73,10 +74,12 @@ module Mongo
|
|
73
74
|
true
|
74
75
|
end
|
75
76
|
|
76
|
-
|
77
|
+
protected
|
77
78
|
|
78
79
|
attr_reader :upconverter
|
79
80
|
|
81
|
+
private
|
82
|
+
|
80
83
|
# The operation code required to specify a GetMore message.
|
81
84
|
# @return [Fixnum] the operation code.
|
82
85
|
def op_code
|
@@ -54,6 +54,8 @@ module Mongo
|
|
54
54
|
@documents = documents
|
55
55
|
@flags = options[:flags] || []
|
56
56
|
@upconverter = Upconverter.new(collection, documents, options)
|
57
|
+
@options = options
|
58
|
+
super
|
57
59
|
end
|
58
60
|
|
59
61
|
# Return the event payload for monitoring.
|
@@ -73,14 +75,16 @@ module Mongo
|
|
73
75
|
}
|
74
76
|
end
|
75
77
|
|
78
|
+
protected
|
79
|
+
|
80
|
+
attr_reader :upconverter
|
81
|
+
|
76
82
|
private
|
77
83
|
|
78
84
|
def validating_keys?
|
79
|
-
true
|
85
|
+
@options.fetch(:validating_keys, true)
|
80
86
|
end
|
81
87
|
|
82
|
-
attr_reader :upconverter
|
83
|
-
|
84
88
|
# The operation code required to specify an Insert message.
|
85
89
|
# @return [Fixnum] the operation code.
|
86
90
|
def op_code
|
@@ -36,6 +36,7 @@ module Mongo
|
|
36
36
|
@cursor_ids = cursor_ids
|
37
37
|
@id_count = @cursor_ids.size
|
38
38
|
@upconverter = Upconverter.new(collection, cursor_ids)
|
39
|
+
super
|
39
40
|
end
|
40
41
|
|
41
42
|
# Return the event payload for monitoring.
|
@@ -55,10 +56,12 @@ module Mongo
|
|
55
56
|
}
|
56
57
|
end
|
57
58
|
|
58
|
-
|
59
|
+
protected
|
59
60
|
|
60
61
|
attr_reader :upconverter
|
61
62
|
|
63
|
+
private
|
64
|
+
|
62
65
|
# The operation code required to specify +KillCursors+ message.
|
63
66
|
# @return [Fixnum] the operation code.
|
64
67
|
def op_code
|
@@ -77,6 +77,10 @@ module Mongo
|
|
77
77
|
# @return [Fixnum] The request id for this message
|
78
78
|
attr_reader :request_id
|
79
79
|
|
80
|
+
def initialize(*args) # :nodoc:
|
81
|
+
@request_id = nil
|
82
|
+
end
|
83
|
+
|
80
84
|
# The default for messages is not to require a reply after sending a
|
81
85
|
# message to the server.
|
82
86
|
#
|
@@ -110,7 +114,7 @@ module Mongo
|
|
110
114
|
#
|
111
115
|
# @return [ Message ] Instance of a Message class
|
112
116
|
def self.deserialize(io, max_message_size = MAX_MESSAGE_SIZE, expected_response_to = nil)
|
113
|
-
length,
|
117
|
+
length, _request_id, response_to, _op_code = deserialize_header(BSON::ByteBuffer.new(io.read(16)))
|
114
118
|
|
115
119
|
# Protection from potential DOS man-in-the-middle attacks. See
|
116
120
|
# DRIVERS-276.
|
data/lib/mongo/protocol/query.rb
CHANGED
@@ -67,6 +67,7 @@ module Mongo
|
|
67
67
|
@skip = options[:skip] || 0
|
68
68
|
@flags = options[:flags] || []
|
69
69
|
@upconverter = Upconverter.new(collection, selector, options, flags)
|
70
|
+
super
|
70
71
|
end
|
71
72
|
|
72
73
|
# Return the event payload for monitoring.
|
@@ -98,10 +99,12 @@ module Mongo
|
|
98
99
|
true
|
99
100
|
end
|
100
101
|
|
101
|
-
|
102
|
+
protected
|
102
103
|
|
103
104
|
attr_reader :upconverter
|
104
105
|
|
106
|
+
private
|
107
|
+
|
105
108
|
# The operation code required to specify a Query message.
|
106
109
|
# @return [Fixnum] the operation code.
|
107
110
|
def op_code
|
@@ -252,7 +255,7 @@ module Mongo
|
|
252
255
|
#
|
253
256
|
# @since 2.1.0
|
254
257
|
def command_name
|
255
|
-
command? ? filter.keys.first
|
258
|
+
(filter[:$query] || !command?) ? FIND : filter.keys.first
|
256
259
|
end
|
257
260
|
|
258
261
|
private
|
@@ -261,9 +264,13 @@ module Mongo
|
|
261
264
|
collection == Database::COMMAND
|
262
265
|
end
|
263
266
|
|
267
|
+
def query_filter
|
268
|
+
filter[:$query] || filter
|
269
|
+
end
|
270
|
+
|
264
271
|
def op_command
|
265
272
|
document = BSON::Document.new
|
266
|
-
|
273
|
+
query_filter.each do |field, value|
|
267
274
|
document.store(field.to_s, value)
|
268
275
|
end
|
269
276
|
document
|
@@ -272,7 +279,7 @@ module Mongo
|
|
272
279
|
def find_command
|
273
280
|
document = BSON::Document.new
|
274
281
|
document.store(FIND, collection)
|
275
|
-
document.store(FILTER,
|
282
|
+
document.store(FILTER, query_filter)
|
276
283
|
OPTION_MAPPINGS.each do |legacy, option|
|
277
284
|
document.store(option, options[legacy]) unless options[legacy].nil?
|
278
285
|
end
|