mongo 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +3 -1
- data/lib/csasl/csasl.bundle +0 -0
- data/lib/mongo/collection/view/builder/find_command.rb +20 -5
- data/lib/mongo/cursor/builder/get_more_command.rb +3 -2
- data/lib/mongo/operation/write/create_index.rb +1 -1
- data/lib/mongo/protocol/insert.rb +2 -1
- data/lib/mongo/protocol/query.rb +7 -3
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/collection/view/builder/find_command_spec.rb +244 -2
- data/spec/mongo/index/view_spec.rb +20 -1
- data/spec/support/crud/read.rb +18 -1
- metadata +3 -2
- 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: b2d9e9f00a79f50cd0a8acbfde72ceb13993a77d
|
4
|
+
data.tar.gz: 90cea8a2fe4251801c0cc40fdca77856c1c6b153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c39d5f4e21bf2ce5390f3cd9baab0dd67f350794b33f41f0deb08a65993b9c669cdbfbe7d2008d8a8105cfcf319da526e557848580f41c1e7c78ac63a40267f9
|
7
|
+
data.tar.gz: 55be4b7a6f20d2ed52dfd15d010391112927925bd3261c8c7d14a468460151a5dba91197983061004c600cf40b84b402a8d5227a670bdae1495fa845951b8a9c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1 +1,3 @@
|
|
1
|
-
|
1
|
+
��V+f�ӱAbc��F�>��NRή��{�#2�%�S!����!TKV�ض�x� �*�9�z+2�c�;�`v_��o�>�/��C،Ve�J��pH�AL��I�{�m8���r3��m%��Y��$0ρ_ií�X�o�:*�����0����l��u�\j͎h]�-���7]4fy�����a.t#�Q'��mR�2/�/{����
|
2
|
+
z+|79��3(���C�����P�����-
|
3
|
+
�\E�zݝ���"��Y�
|
Binary file
|
@@ -95,15 +95,30 @@ module Mongo
|
|
95
95
|
def find_command
|
96
96
|
document = BSON::Document.new('find' => collection.name, 'filter' => filter)
|
97
97
|
command = Options::Mapper.transform_documents(convert_flags(options), MAPPINGS, document)
|
98
|
-
|
98
|
+
convert_limit_and_batch_size(command)
|
99
|
+
command
|
99
100
|
end
|
100
101
|
|
101
|
-
def
|
102
|
-
if command[:limit] && command[:limit] < 0
|
103
|
-
|
102
|
+
def convert_limit_and_batch_size(command)
|
103
|
+
if command[:limit] && command[:limit] < 0 &&
|
104
|
+
command[:batchSize] && command[:batchSize] < 0
|
105
|
+
|
106
|
+
command[:limit] = command[:limit].abs
|
107
|
+
command[:batchSize] = command[:limit].abs
|
104
108
|
command[:singleBatch] = true
|
109
|
+
|
110
|
+
else
|
111
|
+
[:limit, :batchSize].each do |opt|
|
112
|
+
if command[opt]
|
113
|
+
if command[opt] < 0
|
114
|
+
command[opt] = command[opt].abs
|
115
|
+
command[:singleBatch] = true
|
116
|
+
elsif command[opt] == 0
|
117
|
+
command.delete(opt)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
105
121
|
end
|
106
|
-
command
|
107
122
|
end
|
108
123
|
|
109
124
|
def convert_flags(options)
|
@@ -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)
|
@@ -54,6 +54,7 @@ module Mongo
|
|
54
54
|
@documents = documents
|
55
55
|
@flags = options[:flags] || []
|
56
56
|
@upconverter = Upconverter.new(collection, documents, options)
|
57
|
+
@options = options
|
57
58
|
end
|
58
59
|
|
59
60
|
# Return the event payload for monitoring.
|
@@ -76,7 +77,7 @@ module Mongo
|
|
76
77
|
private
|
77
78
|
|
78
79
|
def validating_keys?
|
79
|
-
true
|
80
|
+
@options.fetch(:validating_keys, true)
|
80
81
|
end
|
81
82
|
|
82
83
|
attr_reader :upconverter
|
data/lib/mongo/protocol/query.rb
CHANGED
@@ -252,7 +252,7 @@ module Mongo
|
|
252
252
|
#
|
253
253
|
# @since 2.1.0
|
254
254
|
def command_name
|
255
|
-
command? ? filter.keys.first
|
255
|
+
(filter[:$query] || !command?) ? FIND : filter.keys.first
|
256
256
|
end
|
257
257
|
|
258
258
|
private
|
@@ -261,9 +261,13 @@ module Mongo
|
|
261
261
|
collection == Database::COMMAND
|
262
262
|
end
|
263
263
|
|
264
|
+
def query_filter
|
265
|
+
filter[:$query] || filter
|
266
|
+
end
|
267
|
+
|
264
268
|
def op_command
|
265
269
|
document = BSON::Document.new
|
266
|
-
|
270
|
+
query_filter.each do |field, value|
|
267
271
|
document.store(field.to_s, value)
|
268
272
|
end
|
269
273
|
document
|
@@ -272,7 +276,7 @@ module Mongo
|
|
272
276
|
def find_command
|
273
277
|
document = BSON::Document.new
|
274
278
|
document.store(FIND, collection)
|
275
|
-
document.store(FILTER,
|
279
|
+
document.store(FILTER, query_filter)
|
276
280
|
OPTION_MAPPINGS.each do |legacy, option|
|
277
281
|
document.store(option, options[legacy]) unless options[legacy].nil?
|
278
282
|
end
|
data/lib/mongo/version.rb
CHANGED
@@ -145,14 +145,256 @@ describe Mongo::Collection::View::Builder::FindCommand do
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
|
148
|
+
|
149
|
+
context 'when there is a limit' do
|
150
|
+
|
151
|
+
let(:filter) do
|
152
|
+
{ 'name' => 'test' }
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when limit is 0' do
|
156
|
+
|
157
|
+
context 'when batch_size is also 0' do
|
158
|
+
|
159
|
+
let(:options) do
|
160
|
+
{ limit: 0, batch_size: 0 }
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'does not set the singleBatch' do
|
164
|
+
expect(selector['singleBatch']).to be nil
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'does not set the limit' do
|
168
|
+
expect(selector['limit']).to be nil
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'does not set the batch size' do
|
172
|
+
expect(selector['batchSize']).to be nil
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when batch_size is not set' do
|
177
|
+
|
178
|
+
let(:options) do
|
179
|
+
{ limit: 0 }
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'does not set the singleBatch' do
|
183
|
+
expect(selector['singleBatch']).to be nil
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'does not set the limit' do
|
187
|
+
expect(selector['limit']).to be nil
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'does not set the batch size' do
|
191
|
+
expect(selector['batchSize']).to be nil
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'when the limit is negative' do
|
197
|
+
|
198
|
+
context 'when there is a batch_size' do
|
199
|
+
|
200
|
+
context 'when the batch_size is positive' do
|
201
|
+
|
202
|
+
let(:options) do
|
203
|
+
{ limit: -1, batch_size: 3 }
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'sets single batch to true' do
|
207
|
+
expect(selector['singleBatch']).to be true
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'converts the limit to a positive value' do
|
211
|
+
expect(selector['limit']).to be(options[:limit].abs)
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'sets the batch size' do
|
215
|
+
expect(selector['batchSize']).to be(options[:batch_size])
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'when the batch_size is negative' do
|
220
|
+
|
221
|
+
let(:options) do
|
222
|
+
{ limit: -1, batch_size: -3 }
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'sets single batch to true' do
|
226
|
+
expect(selector['singleBatch']).to be true
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'converts the limit to a positive value' do
|
230
|
+
expect(selector['limit']).to be(options[:limit].abs)
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'sets the batch size to the limit' do
|
234
|
+
expect(selector['batchSize']).to be(options[:limit].abs)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'when there is not a batch_size' do
|
240
|
+
|
241
|
+
let(:options) do
|
242
|
+
{ limit: -5 }
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'sets single batch to true' do
|
246
|
+
expect(selector['singleBatch']).to be true
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'converts the limit to a positive value' do
|
250
|
+
expect(selector['limit']).to be(options[:limit].abs)
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'does not set the batch size' do
|
254
|
+
expect(selector['batchSize']).to be_nil
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'when the limit is positive' do
|
260
|
+
|
261
|
+
context 'when there is a batch_size' do
|
262
|
+
|
263
|
+
context 'when the batch_size is positive' do
|
264
|
+
|
265
|
+
let(:options) do
|
266
|
+
{ limit: 5, batch_size: 3 }
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'does not set singleBatch' do
|
270
|
+
expect(selector['singleBatch']).to be nil
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'sets the limit' do
|
274
|
+
expect(selector['limit']).to be(options[:limit])
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'sets the batch size' do
|
278
|
+
expect(selector['batchSize']).to be(options[:batch_size])
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
context 'when the batch_size is negative' do
|
283
|
+
|
284
|
+
let(:options) do
|
285
|
+
{ limit: 5, batch_size: -3 }
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'sets the singleBatch' do
|
289
|
+
expect(selector['singleBatch']).to be true
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'sets the limit' do
|
293
|
+
expect(selector['limit']).to be(options[:limit])
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'sets the batch size to a positive value' do
|
297
|
+
expect(selector['batchSize']).to be(options[:batch_size].abs)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
context 'when there is not a batch_size' do
|
303
|
+
|
304
|
+
let(:options) do
|
305
|
+
{ limit: 5 }
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'does not set the singleBatch' do
|
309
|
+
expect(selector['singleBatch']).to be nil
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'sets the limit' do
|
313
|
+
expect(selector['limit']).to be(options[:limit])
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'does not set the batch size' do
|
317
|
+
expect(selector['batchSize']).to be nil
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context 'when there is a batch_size' do
|
324
|
+
|
325
|
+
let(:filter) do
|
326
|
+
{ 'name' => 'test' }
|
327
|
+
end
|
328
|
+
|
329
|
+
context 'when there is no limit' do
|
330
|
+
|
331
|
+
context 'when the batch_size is positive' do
|
332
|
+
|
333
|
+
let(:options) do
|
334
|
+
{ batch_size: 3 }
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'does not set the singleBatch' do
|
338
|
+
expect(selector['singleBatch']).to be nil
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'does not set the limit' do
|
342
|
+
expect(selector['limit']).to be nil
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'sets the batch size' do
|
346
|
+
expect(selector['batchSize']).to be(options[:batch_size])
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
context 'when the batch_size is negative' do
|
351
|
+
|
352
|
+
let(:options) do
|
353
|
+
{ batch_size: -3 }
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'sets the singleBatch' do
|
357
|
+
expect(selector['singleBatch']).to be true
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'does not set the limit' do
|
361
|
+
expect(selector['limit']).to be nil
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'sets the batch size to a positive value' do
|
365
|
+
expect(selector['batchSize']).to be(options[:batch_size].abs)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
context 'when batch_size is 0' do
|
370
|
+
|
371
|
+
let(:options) do
|
372
|
+
{ batch_size: 0 }
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'does not set the singleBatch' do
|
376
|
+
expect(selector['singleBatch']).to be nil
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'does not set the limit' do
|
380
|
+
expect(selector['limit']).to be nil
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'does not set the batch size' do
|
384
|
+
expect(selector['batchSize']).to be nil
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
context 'when limit and batch_size are negative' do
|
149
391
|
|
150
392
|
let(:filter) do
|
151
393
|
{ 'name' => 'test' }
|
152
394
|
end
|
153
395
|
|
154
396
|
let(:options) do
|
155
|
-
{ limit: -1 }
|
397
|
+
{ limit: -1, batch_size: -3 }
|
156
398
|
end
|
157
399
|
|
158
400
|
it 'sets single batch to true' do
|
@@ -141,12 +141,31 @@ describe Mongo::Index::View do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
after do
|
144
|
-
view.drop_one('random_1')
|
144
|
+
begin; view.drop_one('random_1'); rescue; end
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'returns ok' do
|
148
148
|
expect(result).to be_successful
|
149
149
|
end
|
150
|
+
|
151
|
+
context 'when the index is created on an subdocument field' do
|
152
|
+
|
153
|
+
let(:spec) do
|
154
|
+
{ 'sub_document.random' => 1 }
|
155
|
+
end
|
156
|
+
|
157
|
+
let(:result) do
|
158
|
+
view.create_one(spec, unique: true)
|
159
|
+
end
|
160
|
+
|
161
|
+
after do
|
162
|
+
begin; view.drop_one('sub_document.random_1'); rescue; end
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'returns ok' do
|
166
|
+
expect(result).to be_successful
|
167
|
+
end
|
168
|
+
end
|
150
169
|
end
|
151
170
|
|
152
171
|
context 'when index creation fails' do
|
data/spec/support/crud/read.rb
CHANGED
@@ -31,6 +31,16 @@ module Mongo
|
|
31
31
|
:limit => 'limit'
|
32
32
|
}
|
33
33
|
|
34
|
+
# Map of read preference mode names to their equivalent Ruby-formatted symbols.
|
35
|
+
#
|
36
|
+
# @since 2.4.0
|
37
|
+
READ_PREFERENCE_MAP = { 'primary' => :primary,
|
38
|
+
'secondary' => :secondary,
|
39
|
+
'primaryPreferred' => :primary_preferred,
|
40
|
+
'secondaryPreferred' => :secondary_preferred,
|
41
|
+
'nearest' => :nearest
|
42
|
+
}
|
43
|
+
|
34
44
|
# The operation name.
|
35
45
|
#
|
36
46
|
# @return [ String ] name The operation name.
|
@@ -109,7 +119,8 @@ module Mongo
|
|
109
119
|
end
|
110
120
|
|
111
121
|
def find(collection)
|
112
|
-
|
122
|
+
opts = modifiers ? options.merge(modifiers: BSON::Document.new(modifiers)) : options
|
123
|
+
(read_preference ? collection.with(read: read_preference) : collection).find(filter, opts).to_a
|
113
124
|
end
|
114
125
|
|
115
126
|
def options
|
@@ -141,6 +152,12 @@ module Mongo
|
|
141
152
|
def arguments
|
142
153
|
@spec['arguments']
|
143
154
|
end
|
155
|
+
|
156
|
+
def read_preference
|
157
|
+
if @spec['read_preference'] && @spec['read_preference']['mode']
|
158
|
+
{ mode: READ_PREFERENCE_MAP[@spec['read_preference']['mode']] }
|
159
|
+
end
|
160
|
+
end
|
144
161
|
end
|
145
162
|
end
|
146
163
|
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.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Brock
|
@@ -32,7 +32,7 @@ cert_chain:
|
|
32
32
|
EhIn2f8suSc9QAqYt7w4T+PMtjxWTVcXs+Uy2PbDtjhtEBz6ZsP6YSsOpJbrCjCV
|
33
33
|
wZtXjpRUvWz86V5vjhHCTE8fqfEb85aeDwUCckPzpio=
|
34
34
|
-----END CERTIFICATE-----
|
35
|
-
date: 2016-
|
35
|
+
date: 2016-11-01 00:00:00.000000000 Z
|
36
36
|
dependencies:
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bson
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- README.md
|
61
61
|
- Rakefile
|
62
62
|
- bin/mongo_console
|
63
|
+
- lib/csasl/csasl.bundle
|
63
64
|
- lib/mongo.rb
|
64
65
|
- lib/mongo/address.rb
|
65
66
|
- lib/mongo/address/ipv4.rb
|
metadata.gz.sig
CHANGED
Binary file
|