mongo 2.0.6 → 2.1.0.beta
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.rb +2 -0
- data/lib/mongo/bulk_write.rb +1 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +87 -31
- data/lib/mongo/bulk_write/deletable.rb +8 -7
- data/lib/mongo/bulk_write/insertable.rb +4 -3
- data/lib/mongo/bulk_write/ordered_bulk_write.rb +6 -6
- data/lib/mongo/bulk_write/replacable.rb +4 -3
- data/lib/mongo/bulk_write/result.rb +138 -0
- data/lib/mongo/bulk_write/unordered_bulk_write.rb +5 -8
- data/lib/mongo/bulk_write/updatable.rb +8 -7
- data/lib/mongo/client.rb +36 -4
- data/lib/mongo/cluster.rb +39 -4
- data/lib/mongo/cluster/topology/replica_set.rb +20 -4
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/collection.rb +282 -29
- data/lib/mongo/collection/view/aggregation.rb +32 -4
- data/lib/mongo/collection/view/iterable.rb +2 -1
- data/lib/mongo/collection/view/map_reduce.rb +3 -1
- data/lib/mongo/collection/view/readable.rb +89 -14
- data/lib/mongo/collection/view/writable.rb +11 -5
- data/lib/mongo/cursor.rb +11 -3
- data/lib/mongo/dbref.rb +113 -0
- data/lib/mongo/error.rb +6 -2
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/grid/file.rb +1 -1
- data/lib/mongo/grid/fs.rb +2 -5
- data/lib/mongo/monitoring.rb +199 -0
- data/lib/mongo/monitoring/command_log_subscriber.rb +88 -0
- data/lib/mongo/monitoring/event.rb +17 -0
- data/lib/mongo/monitoring/event/command_failed.rb +96 -0
- data/lib/mongo/monitoring/event/command_started.rb +88 -0
- data/lib/mongo/monitoring/event/command_succeeded.rb +96 -0
- data/lib/mongo/monitoring/publishable.rb +96 -0
- data/lib/mongo/operation.rb +1 -0
- data/lib/mongo/operation/executable.rb +1 -1
- data/lib/mongo/operation/parallel_scan.rb +76 -0
- data/lib/mongo/operation/parallel_scan/result.rb +72 -0
- data/lib/mongo/operation/specifiable.rb +18 -0
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +2 -2
- data/lib/mongo/operation/write/bulk/bulk_update.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +13 -1
- data/lib/mongo/protocol/delete.rb +8 -13
- data/lib/mongo/protocol/get_more.rb +13 -13
- data/lib/mongo/protocol/insert.rb +8 -13
- data/lib/mongo/protocol/kill_cursors.rb +7 -11
- data/lib/mongo/protocol/query.rb +58 -20
- data/lib/mongo/protocol/reply.rb +12 -0
- data/lib/mongo/protocol/update.rb +13 -14
- data/lib/mongo/server.rb +23 -2
- data/lib/mongo/server/connectable.rb +0 -22
- data/lib/mongo/server/connection.rb +29 -0
- data/lib/mongo/server/description.rb +23 -1
- data/lib/mongo/server/monitor.rb +17 -1
- data/lib/mongo/server/monitor/connection.rb +24 -0
- data/lib/mongo/socket/ssl.rb +28 -16
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/socket/unix.rb +1 -1
- data/lib/mongo/uri.rb +12 -5
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/auth/cr_spec.rb +9 -1
- data/spec/mongo/auth/ldap_spec.rb +9 -1
- data/spec/mongo/auth/scram_spec.rb +9 -1
- data/spec/mongo/auth/x509_spec.rb +9 -1
- data/spec/mongo/{bulk/bulk_write_spec.rb → bulk_write_spec.rb} +15 -15
- data/spec/mongo/client_spec.rb +42 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -9
- data/spec/mongo/cluster/topology/sharded_spec.rb +11 -3
- data/spec/mongo/cluster/topology/single_spec.rb +12 -4
- data/spec/mongo/cluster_spec.rb +55 -10
- data/spec/mongo/collection/view/aggregation_spec.rb +123 -1
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
- data/spec/mongo/collection/view/readable_spec.rb +251 -6
- data/spec/mongo/collection/view/writable_spec.rb +4 -4
- data/spec/mongo/collection/view_spec.rb +233 -71
- data/spec/mongo/collection_spec.rb +905 -9
- data/spec/mongo/crud_spec.rb +2 -2
- data/spec/mongo/cursor_spec.rb +3 -3
- data/spec/mongo/dbref_spec.rb +149 -0
- data/spec/mongo/monitoring_spec.rb +168 -0
- data/spec/mongo/operation/map_reduce_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_delete_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_insert_spec.rb +2 -2
- data/spec/mongo/operation/write/bulk/bulk_update_spec.rb +1 -1
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +2 -2
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/protocol/query_spec.rb +0 -29
- data/spec/mongo/server/connection_pool_spec.rb +18 -6
- data/spec/mongo/server/connection_spec.rb +12 -4
- data/spec/mongo/server/description_spec.rb +7 -3
- data/spec/mongo/server/monitor_spec.rb +30 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +11 -4
- data/spec/mongo/server_selection_spec.rb +14 -6
- data/spec/mongo/server_spec.rb +27 -8
- data/spec/mongo/socket/ssl_spec.rb +94 -8
- data/spec/mongo/uri_spec.rb +25 -9
- data/spec/spec_helper.rb +29 -20
- data/spec/support/authorization.rb +19 -4
- data/spec/support/certificates/client.pem +4 -4
- data/spec/support/crud/read.rb +9 -10
- data/spec/support/crud/write.rb +24 -20
- data/spec/support/sdam/rs/equal_electionids.yml +45 -0
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +98 -0
- data/spec/support/sdam/rs/null_election_id.yml +144 -0
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +124 -0
- data/spec/support/sdam/sharded/mongos_disconnect.yml +104 -0
- data/spec/support/server_discovery_and_monitoring.rb +19 -2
- data/spec/support/shared/bulk_write.rb +26 -22
- data/spec/support/shared/server_selector.rb +2 -1
- metadata +31 -7
- metadata.gz.sig +0 -0
- data/lib/mongo/error/invalid_uri_option.rb +0 -38
data/spec/mongo/client_spec.rb
CHANGED
@@ -448,6 +448,17 @@ describe Mongo::Client do
|
|
448
448
|
|
449
449
|
describe '#with' do
|
450
450
|
|
451
|
+
let(:client) do
|
452
|
+
described_class.new(['127.0.0.1:27017'], :database => TEST_DB)
|
453
|
+
end
|
454
|
+
|
455
|
+
context 'when providing nil' do
|
456
|
+
|
457
|
+
it 'returns the cloned client' do
|
458
|
+
expect(client.with(nil)).to eq(client)
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
451
462
|
context 'when the write concern is not changed' do
|
452
463
|
|
453
464
|
let(:client) do
|
@@ -592,4 +603,35 @@ describe Mongo::Client do
|
|
592
603
|
end).to include('admin')
|
593
604
|
end
|
594
605
|
end
|
606
|
+
|
607
|
+
describe '#close' do
|
608
|
+
|
609
|
+
let(:client) do
|
610
|
+
described_class.new(['127.0.0.1:27017'])
|
611
|
+
end
|
612
|
+
|
613
|
+
before do
|
614
|
+
expect(client.cluster).to receive(:disconnect!).and_call_original
|
615
|
+
end
|
616
|
+
|
617
|
+
it 'disconnects the cluster and returns true' do
|
618
|
+
expect(client.close).to be(true)
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
622
|
+
describe '#reconnect' do
|
623
|
+
|
624
|
+
let(:client) do
|
625
|
+
described_class.new(['127.0.0.1:27017'])
|
626
|
+
end
|
627
|
+
|
628
|
+
before do
|
629
|
+
expect(client.cluster).to receive(:reconnect!).and_call_original
|
630
|
+
end
|
631
|
+
|
632
|
+
it 'reconnects the cluster and returns true' do
|
633
|
+
expect(client.reconnect).to be(true)
|
634
|
+
sleep(2)
|
635
|
+
end
|
636
|
+
end
|
595
637
|
end
|
@@ -6,22 +6,30 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
6
6
|
Mongo::Address.new('127.0.0.1:27017')
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:listeners) do
|
10
|
+
Mongo::Event::Listeners.new
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:monitoring) do
|
14
|
+
Mongo::Monitoring.new
|
15
|
+
end
|
16
|
+
|
9
17
|
describe '#servers' do
|
10
18
|
|
11
19
|
let(:mongos) do
|
12
|
-
Mongo::Server.new(address, double('cluster'),
|
20
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
13
21
|
end
|
14
22
|
|
15
23
|
let(:standalone) do
|
16
|
-
Mongo::Server.new(address, double('cluster'),
|
24
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
17
25
|
end
|
18
26
|
|
19
27
|
let(:replica_set) do
|
20
|
-
Mongo::Server.new(address, double('cluster'),
|
28
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
21
29
|
end
|
22
30
|
|
23
31
|
let(:replica_set_two) do
|
24
|
-
Mongo::Server.new(address, double('cluster'),
|
32
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
25
33
|
end
|
26
34
|
|
27
35
|
let(:mongos_description) do
|
@@ -102,11 +110,11 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
102
110
|
describe '#add_hosts?' do
|
103
111
|
|
104
112
|
let(:primary) do
|
105
|
-
Mongo::Server.new(address, double('cluster'),
|
113
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
106
114
|
end
|
107
115
|
|
108
116
|
let(:secondary) do
|
109
|
-
Mongo::Server.new(address, double('cluster'),
|
117
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
110
118
|
end
|
111
119
|
|
112
120
|
let(:primary_description) do
|
@@ -183,7 +191,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
183
191
|
describe '#remove_hosts?' do
|
184
192
|
|
185
193
|
let(:primary) do
|
186
|
-
Mongo::Server.new(address, double('cluster'),
|
194
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
187
195
|
end
|
188
196
|
|
189
197
|
let(:primary_description) do
|
@@ -262,7 +270,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
262
270
|
describe '#remove_server?' do
|
263
271
|
|
264
272
|
let(:secondary) do
|
265
|
-
Mongo::Server.new(address, double('cluster'),
|
273
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
266
274
|
end
|
267
275
|
|
268
276
|
let(:secondary_description) do
|
@@ -346,6 +354,5 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
346
354
|
expect(topology.remove_server?(description, secondary)).to eq(false)
|
347
355
|
end
|
348
356
|
end
|
349
|
-
|
350
357
|
end
|
351
358
|
end
|
@@ -10,17 +10,24 @@ describe Mongo::Cluster::Topology::Sharded do
|
|
10
10
|
described_class.new({})
|
11
11
|
end
|
12
12
|
|
13
|
+
let(:monitoring) do
|
14
|
+
Mongo::Monitoring.new
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:listeners) do
|
18
|
+
Mongo::Event::Listeners.new
|
19
|
+
end
|
13
20
|
|
14
21
|
let(:mongos) do
|
15
|
-
Mongo::Server.new(address, double('cluster'),
|
22
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
16
23
|
end
|
17
24
|
|
18
25
|
let(:standalone) do
|
19
|
-
Mongo::Server.new(address, double('cluster'),
|
26
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
20
27
|
end
|
21
28
|
|
22
29
|
let(:replica_set) do
|
23
|
-
Mongo::Server.new(address, double('cluster'),
|
30
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
24
31
|
end
|
25
32
|
|
26
33
|
let(:mongos_description) do
|
@@ -99,6 +106,7 @@ describe Mongo::Cluster::Topology::Sharded do
|
|
99
106
|
let(:description) do
|
100
107
|
double('description').tap do |d|
|
101
108
|
allow(d).to receive(:mongos?).and_return(false)
|
109
|
+
allow(d).to receive(:unknown?).and_return(false)
|
102
110
|
allow(d).to receive(:is_server?).and_return(true)
|
103
111
|
end
|
104
112
|
end
|
@@ -10,22 +10,30 @@ describe Mongo::Cluster::Topology::Single do
|
|
10
10
|
described_class.new({})
|
11
11
|
end
|
12
12
|
|
13
|
+
let(:monitoring) do
|
14
|
+
Mongo::Monitoring.new
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:listeners) do
|
18
|
+
Mongo::Event::Listeners.new
|
19
|
+
end
|
20
|
+
|
13
21
|
describe '.servers' do
|
14
22
|
|
15
23
|
let(:mongos) do
|
16
|
-
Mongo::Server.new(address, double('cluster'),
|
24
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
17
25
|
end
|
18
26
|
|
19
27
|
let(:standalone) do
|
20
|
-
Mongo::Server.new(address, double('cluster'),
|
28
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
21
29
|
end
|
22
30
|
|
23
31
|
let(:standalone_two) do
|
24
|
-
Mongo::Server.new(address, double('cluster'),
|
32
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
25
33
|
end
|
26
34
|
|
27
35
|
let(:replica_set) do
|
28
|
-
Mongo::Server.new(address, double('cluster'),
|
36
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
29
37
|
end
|
30
38
|
|
31
39
|
let(:mongos_description) do
|
data/spec/mongo/cluster_spec.rb
CHANGED
@@ -2,8 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Cluster do
|
4
4
|
|
5
|
+
let(:monitoring) do
|
6
|
+
Mongo::Monitoring.new
|
7
|
+
end
|
8
|
+
|
5
9
|
let(:cluster) do
|
6
|
-
described_class.new(ADDRESSES, TEST_OPTIONS)
|
10
|
+
described_class.new(ADDRESSES, monitoring, TEST_OPTIONS)
|
7
11
|
end
|
8
12
|
|
9
13
|
describe '#==' do
|
@@ -15,7 +19,7 @@ describe Mongo::Cluster do
|
|
15
19
|
context 'when the options are the same' do
|
16
20
|
|
17
21
|
let(:other) do
|
18
|
-
described_class.new(ADDRESSES, TEST_OPTIONS)
|
22
|
+
described_class.new(ADDRESSES, monitoring, TEST_OPTIONS)
|
19
23
|
end
|
20
24
|
|
21
25
|
it 'returns true' do
|
@@ -26,7 +30,7 @@ describe Mongo::Cluster do
|
|
26
30
|
context 'when the options are not the same' do
|
27
31
|
|
28
32
|
let(:other) do
|
29
|
-
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS.merge(:replica_set => 'test'))
|
33
|
+
described_class.new([ '127.0.0.1:27017' ], monitoring, TEST_OPTIONS.merge(:replica_set => 'test'))
|
30
34
|
end
|
31
35
|
|
32
36
|
it 'returns false' do
|
@@ -38,7 +42,7 @@ describe Mongo::Cluster do
|
|
38
42
|
context 'when the addresses are not the same' do
|
39
43
|
|
40
44
|
let(:other) do
|
41
|
-
described_class.new([ '127.0.0.1:27018' ], TEST_OPTIONS)
|
45
|
+
described_class.new([ '127.0.0.1:27018' ], monitoring, TEST_OPTIONS)
|
42
46
|
end
|
43
47
|
|
44
48
|
it 'returns false' do
|
@@ -76,8 +80,11 @@ describe Mongo::Cluster do
|
|
76
80
|
context 'when the option is provided' do
|
77
81
|
|
78
82
|
let(:cluster) do
|
79
|
-
described_class.new(
|
80
|
-
|
83
|
+
described_class.new(
|
84
|
+
[ '127.0.0.1:27017' ],
|
85
|
+
monitoring,
|
86
|
+
TEST_OPTIONS.merge(:connect => :replica_set, :replica_set => 'testing')
|
87
|
+
)
|
81
88
|
end
|
82
89
|
|
83
90
|
it 'returns the name' do
|
@@ -88,7 +95,7 @@ describe Mongo::Cluster do
|
|
88
95
|
context 'when the option is not provided' do
|
89
96
|
|
90
97
|
let(:cluster) do
|
91
|
-
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS.dup.delete_if { |k| k == :replica_set })
|
98
|
+
described_class.new([ '127.0.0.1:27017' ], monitoring, TEST_OPTIONS.dup.delete_if { |k| k == :replica_set })
|
92
99
|
end
|
93
100
|
|
94
101
|
it 'returns nil' do
|
@@ -210,6 +217,36 @@ describe Mongo::Cluster do
|
|
210
217
|
end
|
211
218
|
end
|
212
219
|
|
220
|
+
describe '#disconnect!' do
|
221
|
+
|
222
|
+
let(:known_servers) do
|
223
|
+
cluster.instance_variable_get(:@servers)
|
224
|
+
end
|
225
|
+
|
226
|
+
before do
|
227
|
+
known_servers.each do |server|
|
228
|
+
expect(server).to receive(:disconnect!).and_call_original
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'disconnects each server and returns true' do
|
233
|
+
expect(cluster.disconnect!).to be(true)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe '#reconnect!' do
|
238
|
+
|
239
|
+
before do
|
240
|
+
cluster.servers.each do |server|
|
241
|
+
expect(server).to receive(:reconnect!).and_call_original
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'reconnects each server and returns true' do
|
246
|
+
expect(cluster.reconnect!).to be(true)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
213
250
|
describe '#remove' do
|
214
251
|
|
215
252
|
let(:address_a) do
|
@@ -220,12 +257,16 @@ describe Mongo::Cluster do
|
|
220
257
|
Mongo::Address.new('127.0.0.1:27018')
|
221
258
|
end
|
222
259
|
|
260
|
+
let(:monitoring) do
|
261
|
+
Mongo::Monitoring.new
|
262
|
+
end
|
263
|
+
|
223
264
|
let(:server_a) do
|
224
|
-
Mongo::Server.new(address_a, cluster, Mongo::Event::Listeners.new)
|
265
|
+
Mongo::Server.new(address_a, cluster, monitoring, Mongo::Event::Listeners.new)
|
225
266
|
end
|
226
267
|
|
227
268
|
let(:server_b) do
|
228
|
-
Mongo::Server.new(address_b, cluster, Mongo::Event::Listeners.new)
|
269
|
+
Mongo::Server.new(address_b, cluster, monitoring, Mongo::Event::Listeners.new)
|
229
270
|
end
|
230
271
|
|
231
272
|
let(:servers) do
|
@@ -309,8 +350,12 @@ describe Mongo::Cluster do
|
|
309
350
|
Mongo::Address.new('127.0.0.1:27017')
|
310
351
|
end
|
311
352
|
|
353
|
+
let(:monitoring) do
|
354
|
+
Mongo::Monitoring.new
|
355
|
+
end
|
356
|
+
|
312
357
|
let(:server) do
|
313
|
-
Mongo::Server.new(address, cluster, listeners)
|
358
|
+
Mongo::Server.new(address, cluster, monitoring, listeners)
|
314
359
|
end
|
315
360
|
|
316
361
|
let(:servers) do
|
@@ -61,7 +61,7 @@ describe Mongo::Collection::View::Aggregation do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
after do
|
64
|
-
authorized_collection.
|
64
|
+
authorized_collection.delete_many
|
65
65
|
end
|
66
66
|
|
67
67
|
context 'when a block is provided' do
|
@@ -176,6 +176,128 @@ describe Mongo::Collection::View::Aggregation do
|
|
176
176
|
it 'includes the option in the spec' do
|
177
177
|
expect(aggregation.send(:aggregate_spec)[:selector][:allowDiskUse]).to eq(true)
|
178
178
|
end
|
179
|
+
|
180
|
+
context 'when allow_disk_use is specified as an option' do
|
181
|
+
|
182
|
+
let(:options) do
|
183
|
+
{ :allow_disk_use => true }
|
184
|
+
end
|
185
|
+
|
186
|
+
let(:aggregation) do
|
187
|
+
described_class.new(view, pipeline, options)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'includes the option in the spec' do
|
191
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:allowDiskUse]).to eq(true)
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'when #allow_disk_use is also called' do
|
195
|
+
|
196
|
+
let(:options) do
|
197
|
+
{ :allow_disk_use => true }
|
198
|
+
end
|
199
|
+
|
200
|
+
let(:aggregation) do
|
201
|
+
described_class.new(view, pipeline, options).allow_disk_use(false)
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'overrides the first option with the second' do
|
205
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:allowDiskUse]).to eq(false)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'when max_time_ms is an option' do
|
212
|
+
|
213
|
+
let(:options) do
|
214
|
+
{ :max_time_ms => 100 }
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'includes the option in the spec' do
|
218
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:maxTimeMS]).to eq(options[:max_time_ms])
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'when batch_size is set' do
|
223
|
+
|
224
|
+
context 'when batch_size is set on the view' do
|
225
|
+
|
226
|
+
let(:view_options) do
|
227
|
+
{ :batch_size => 10 }
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'uses the batch_size on the view' do
|
231
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor][:batchSize]).to eq(view_options[:batch_size])
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'when batch_size is provided in the options' do
|
236
|
+
|
237
|
+
let(:options) do
|
238
|
+
{ :batch_size => 20 }
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'includes the option in the spec' do
|
242
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor][:batchSize]).to eq(options[:batch_size])
|
243
|
+
end
|
244
|
+
|
245
|
+
context 'when batch_size is also set on the view' do
|
246
|
+
|
247
|
+
let(:view_options) do
|
248
|
+
{ :batch_size => 10 }
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'overrides the view batch_size with the option batch_size' do
|
252
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor][:batchSize]).to eq(options[:batch_size])
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'when use_cursor is set' do
|
259
|
+
|
260
|
+
context 'when use_cursor is true' do
|
261
|
+
|
262
|
+
context 'when batch_size is set' do
|
263
|
+
|
264
|
+
let(:options) do
|
265
|
+
{ :use_cursor => true,
|
266
|
+
:batch_size => 10
|
267
|
+
}
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'sets a batch size document in the spec' do
|
271
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor][:batchSize]).to eq(options[:batch_size])
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'when batch_size is not set' do
|
276
|
+
|
277
|
+
let(:options) do
|
278
|
+
{ :use_cursor => true }
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'sets an empty document in the spec' do
|
282
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor]).to eq({})
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
context 'when use_cursor is false' do
|
289
|
+
|
290
|
+
let(:options) do
|
291
|
+
{ :use_cursor => false }
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'when batch_size is set' do
|
295
|
+
|
296
|
+
it 'does not set the cursor option in the spec' do
|
297
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor]).to be_nil
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
179
301
|
end
|
180
302
|
end
|
181
303
|
end
|