mongo 2.0.0.beta → 2.0.0.rc
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/Rakefile +14 -1
- data/lib/mongo.rb +2 -1
- data/lib/mongo/auth.rb +2 -2
- data/lib/mongo/bulk_write.rb +52 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +191 -0
- data/lib/mongo/bulk_write/deletable.rb +60 -0
- data/lib/mongo/bulk_write/insertable.rb +52 -0
- data/lib/mongo/bulk_write/ordered_bulk_write.rb +48 -0
- data/lib/mongo/bulk_write/replacable.rb +57 -0
- data/lib/mongo/bulk_write/unordered_bulk_write.rb +46 -0
- data/lib/mongo/bulk_write/updatable.rb +68 -0
- data/lib/mongo/client.rb +15 -2
- data/lib/mongo/cluster/topology/replica_set.rb +1 -1
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/standalone.rb +1 -1
- data/lib/mongo/cluster/topology/unknown.rb +1 -1
- data/lib/mongo/collection.rb +1 -1
- data/lib/mongo/collection/view/aggregation.rb +1 -1
- data/lib/mongo/collection/view/readable.rb +1 -1
- data/lib/mongo/collection/view/writable.rb +5 -5
- data/lib/mongo/cursor.rb +0 -2
- data/lib/mongo/error.rb +4 -3
- data/lib/mongo/error/{bulk_write_failure.rb → bulk_write_error.rb} +2 -2
- data/lib/mongo/error/invalid_bulk_operation.rb +2 -2
- data/lib/mongo/error/invalid_bulk_operation_type.rb +36 -0
- data/lib/mongo/error/{empty_batch.rb → multi_index_drop.rb} +5 -10
- data/lib/mongo/grid/file/metadata.rb +1 -8
- data/lib/mongo/grid/fs.rb +5 -5
- data/lib/mongo/index/view.rb +90 -34
- data/lib/mongo/operation.rb +0 -1
- data/lib/mongo/operation/aggregate.rb +2 -2
- data/lib/mongo/operation/aggregate/result.rb +4 -0
- data/lib/mongo/operation/bulk_delete/result.rb +2 -127
- data/lib/mongo/operation/bulk_insert/result.rb +2 -132
- data/lib/mongo/operation/bulk_update/result.rb +2 -142
- data/lib/mongo/operation/command.rb +1 -1
- data/lib/mongo/operation/executable.rb +3 -3
- data/lib/mongo/operation/list_collections/result.rb +0 -2
- data/lib/mongo/operation/map_reduce.rb +1 -1
- data/lib/mongo/operation/read/collections_info.rb +1 -1
- data/lib/mongo/operation/read/get_more.rb +1 -1
- data/lib/mongo/operation/read/indexes.rb +1 -1
- data/lib/mongo/operation/read/list_collections.rb +1 -1
- data/lib/mongo/operation/read/list_indexes.rb +1 -1
- data/lib/mongo/operation/read/query.rb +1 -1
- data/lib/mongo/operation/specifiable.rb +18 -1
- data/lib/mongo/operation/write.rb +2 -0
- data/lib/mongo/operation/write/bulk_delete.rb +5 -19
- data/lib/mongo/operation/write/bulk_insert.rb +9 -40
- data/lib/mongo/operation/write/bulk_mergable.rb +67 -0
- data/lib/mongo/operation/write/bulk_update.rb +5 -19
- data/lib/mongo/operation/write/command.rb +1 -1
- data/lib/mongo/operation/write/command/{ensure_index.rb → create_index.rb} +4 -9
- data/lib/mongo/operation/write/command/delete.rb +4 -4
- data/lib/mongo/operation/write/command/drop_index.rb +1 -1
- data/lib/mongo/operation/write/command/insert.rb +4 -4
- data/lib/mongo/operation/write/command/update.rb +4 -4
- data/lib/mongo/operation/write/create_index.rb +12 -7
- data/lib/mongo/operation/write/create_user.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +1 -1
- data/lib/mongo/operation/write/drop_index.rb +1 -1
- data/lib/mongo/operation/write/insert.rb +1 -1
- data/lib/mongo/operation/write/legacy_bulk_mergable.rb +83 -0
- data/lib/mongo/operation/write/remove_user.rb +1 -1
- data/lib/mongo/operation/write/update.rb +1 -1
- data/lib/mongo/{bulk.rb → options.rb} +2 -2
- data/lib/mongo/options/mapper.rb +78 -0
- data/lib/mongo/server.rb +2 -2
- data/lib/mongo/server/connection_pool/queue.rb +1 -1
- data/lib/mongo/server/description.rb +1 -1
- data/lib/mongo/server/description/inspector.rb +1 -1
- data/lib/mongo/server_selector.rb +1 -1
- data/lib/mongo/socket/unix.rb +2 -4
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern/acknowledged.rb +15 -1
- data/lib/mongo/write_concern/normalizable.rb +0 -22
- data/lib/mongo/write_concern/unacknowledged.rb +12 -0
- data/spec/mongo/bulk/bulk_write_spec.rb +178 -91
- data/spec/mongo/collection/view/aggregation_spec.rb +14 -1
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
- data/spec/mongo/collection/view/readable_spec.rb +2 -2
- data/spec/mongo/collection/view/writable_spec.rb +7 -7
- data/spec/mongo/collection/view_spec.rb +14 -5
- data/spec/mongo/collection_spec.rb +5 -5
- data/spec/mongo/cursor_spec.rb +3 -3
- data/spec/mongo/database_spec.rb +4 -8
- data/spec/mongo/grid/fs_spec.rb +8 -8
- data/spec/mongo/index/view_spec.rb +139 -35
- data/spec/mongo/operation/aggregate_spec.rb +14 -22
- data/spec/mongo/operation/command_spec.rb +8 -16
- data/spec/mongo/operation/map_reduce_spec.rb +1 -1
- data/spec/mongo/operation/read/indexes_spec.rb +2 -2
- data/spec/mongo/operation/write/bulk_delete_spec.rb +1 -239
- data/spec/mongo/operation/write/bulk_insert_spec.rb +3 -234
- data/spec/mongo/operation/write/bulk_update_spec.rb +1 -289
- data/spec/mongo/operation/write/command/delete_spec.rb +0 -13
- data/spec/mongo/operation/write/command/insert_spec.rb +0 -14
- data/spec/mongo/operation/write/command/update_spec.rb +0 -14
- data/spec/mongo/operation/write/{ensure_index_spec.rb → create_index_spec.rb} +8 -26
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/drop_index_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +3 -3
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/server_selection_spec.rb +2 -2
- data/spec/support/authorization.rb +4 -2
- data/spec/support/server_selection.rb +25 -8
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +4 -10
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +6 -12
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +4 -6
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +4 -10
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +6 -12
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +4 -10
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +4 -10
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +6 -12
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +6 -12
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +9 -17
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +9 -17
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +6 -10
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +11 -21
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +11 -18
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +29 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +26 -0
- data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +4 -10
- data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +2 -6
- data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +0 -2
- data/spec/support/shared/bulk_write.rb +109 -72
- metadata +29 -10
- metadata.gz.sig +0 -0
- data/lib/mongo/bulk/bulk_write.rb +0 -307
- data/lib/mongo/operation/batchable.rb +0 -103
data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml
CHANGED
@@ -2,33 +2,25 @@
|
|
2
2
|
topology_description:
|
3
3
|
type: ReplicaSetWithPrimary
|
4
4
|
servers:
|
5
|
-
-
|
6
|
-
address: b:27017
|
5
|
+
- address: b:27017
|
7
6
|
avg_rtt_ms: 5
|
8
7
|
type: RSSecondary
|
9
|
-
|
10
|
-
|
11
|
-
-
|
12
|
-
address: c:27017
|
8
|
+
tags:
|
9
|
+
data_center: nyc
|
10
|
+
- address: c:27017
|
13
11
|
avg_rtt_ms: 100
|
14
12
|
type: RSSecondary
|
15
|
-
|
16
|
-
|
17
|
-
-
|
18
|
-
address: a:27017
|
13
|
+
tags:
|
14
|
+
data_center: nyc
|
15
|
+
- address: a:27017
|
19
16
|
avg_rtt_ms: 26
|
20
17
|
type: RSPrimary
|
21
|
-
|
22
|
-
|
18
|
+
tags:
|
19
|
+
data_center: nyc
|
23
20
|
operation: read
|
24
21
|
read_preference:
|
25
22
|
mode: Nearest
|
26
23
|
tag_sets:
|
27
24
|
- data_center: sf
|
28
|
-
candidate_servers:
|
29
|
-
- *1
|
30
|
-
- *2
|
31
|
-
- *3
|
32
|
-
eligible_servers: []
|
33
25
|
suitable_servers: []
|
34
26
|
in_latency_window: []
|
@@ -5,28 +5,24 @@ topology_description:
|
|
5
5
|
- address: b:27017
|
6
6
|
avg_rtt_ms: 5
|
7
7
|
type: RSSecondary
|
8
|
-
|
9
|
-
|
8
|
+
tags:
|
9
|
+
data_center: nyc
|
10
10
|
- address: c:27017
|
11
11
|
avg_rtt_ms: 100
|
12
12
|
type: RSSecondary
|
13
|
-
|
14
|
-
|
13
|
+
tags:
|
14
|
+
data_center: nyc
|
15
15
|
- &1
|
16
16
|
address: a:27017
|
17
17
|
avg_rtt_ms: 26
|
18
18
|
type: RSPrimary
|
19
|
-
|
20
|
-
|
19
|
+
tags:
|
20
|
+
data_center: nyc
|
21
21
|
operation: read
|
22
22
|
read_preference:
|
23
23
|
mode: Primary
|
24
24
|
tag_sets:
|
25
25
|
- {}
|
26
|
-
candidate_servers:
|
27
|
-
- *1
|
28
|
-
eligible_servers:
|
29
|
-
- *1
|
30
26
|
suitable_servers:
|
31
27
|
- *1
|
32
28
|
in_latency_window:
|
data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml
CHANGED
@@ -2,38 +2,28 @@
|
|
2
2
|
topology_description:
|
3
3
|
type: ReplicaSetWithPrimary
|
4
4
|
servers:
|
5
|
-
-
|
6
|
-
address: b:27017
|
5
|
+
- address: b:27017
|
7
6
|
avg_rtt_ms: 5
|
8
7
|
type: RSSecondary
|
9
|
-
|
10
|
-
|
11
|
-
-
|
12
|
-
address: c:27017
|
8
|
+
tags:
|
9
|
+
data_center: nyc
|
10
|
+
- address: c:27017
|
13
11
|
avg_rtt_ms: 100
|
14
12
|
type: RSSecondary
|
15
|
-
|
16
|
-
|
17
|
-
- &
|
13
|
+
tags:
|
14
|
+
data_center: nyc
|
15
|
+
- &1
|
18
16
|
address: a:27017
|
19
17
|
avg_rtt_ms: 26
|
20
18
|
type: RSPrimary
|
21
|
-
|
22
|
-
|
19
|
+
tags:
|
20
|
+
data_center: nyc
|
23
21
|
operation: read
|
24
22
|
read_preference:
|
25
23
|
mode: PrimaryPreferred
|
26
24
|
tag_sets:
|
27
25
|
- {}
|
28
|
-
candidate_servers:
|
29
|
-
- *1
|
30
|
-
- *2
|
31
|
-
- *3
|
32
|
-
eligible_servers:
|
33
|
-
- *1
|
34
|
-
- *2
|
35
|
-
- *3
|
36
26
|
suitable_servers:
|
37
|
-
- *
|
27
|
+
- *1
|
38
28
|
in_latency_window:
|
39
|
-
- *
|
29
|
+
- *1
|
@@ -2,35 +2,28 @@
|
|
2
2
|
topology_description:
|
3
3
|
type: ReplicaSetWithPrimary
|
4
4
|
servers:
|
5
|
-
-
|
6
|
-
address: b:27017
|
5
|
+
- address: b:27017
|
7
6
|
avg_rtt_ms: 5
|
8
7
|
type: RSSecondary
|
9
|
-
|
10
|
-
|
11
|
-
-
|
12
|
-
address: c:27017
|
8
|
+
tags:
|
9
|
+
data_center: nyc
|
10
|
+
- address: c:27017
|
13
11
|
avg_rtt_ms: 100
|
14
12
|
type: RSSecondary
|
15
|
-
|
16
|
-
|
17
|
-
- &
|
13
|
+
tags:
|
14
|
+
data_center: nyc
|
15
|
+
- &1
|
18
16
|
address: a:27017
|
19
17
|
avg_rtt_ms: 26
|
20
18
|
type: RSPrimary
|
21
|
-
|
22
|
-
|
19
|
+
tags:
|
20
|
+
data_center: nyc
|
23
21
|
operation: read
|
24
22
|
read_preference:
|
25
23
|
mode: PrimaryPreferred
|
26
24
|
tag_sets:
|
27
25
|
- data_center: sf
|
28
|
-
candidate_servers:
|
29
|
-
- *1
|
30
|
-
- *2
|
31
|
-
- *3
|
32
|
-
eligible_servers: []
|
33
26
|
suitable_servers:
|
34
|
-
- *
|
27
|
+
- *1
|
35
28
|
in_latency_window:
|
36
|
-
- *
|
29
|
+
- *1
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
topology_description:
|
3
|
+
type: ReplicaSetWithPrimary
|
4
|
+
servers:
|
5
|
+
- &1
|
6
|
+
address: b:27017
|
7
|
+
avg_rtt_ms: 5
|
8
|
+
type: RSSecondary
|
9
|
+
tags:
|
10
|
+
data_center: nyc
|
11
|
+
- &2
|
12
|
+
address: c:27017
|
13
|
+
avg_rtt_ms: 100
|
14
|
+
type: RSSecondary
|
15
|
+
tags:
|
16
|
+
data_center: nyc
|
17
|
+
- address: a:27017
|
18
|
+
avg_rtt_ms: 26
|
19
|
+
type: RSPrimary
|
20
|
+
tags:
|
21
|
+
data_center: nyc
|
22
|
+
operation: read
|
23
|
+
read_preference:
|
24
|
+
mode: Secondary
|
25
|
+
tag_sets:
|
26
|
+
- data_center: nyc
|
27
|
+
suitable_servers:
|
28
|
+
- *1
|
29
|
+
- *2
|
30
|
+
in_latency_window:
|
31
|
+
- *1
|
data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
topology_description:
|
3
|
+
type: ReplicaSetWithPrimary
|
4
|
+
servers:
|
5
|
+
- &1
|
6
|
+
address: b:27017
|
7
|
+
avg_rtt_ms: 5
|
8
|
+
type: RSSecondary
|
9
|
+
tags:
|
10
|
+
data_center: nyc
|
11
|
+
- &2
|
12
|
+
address: c:27017
|
13
|
+
avg_rtt_ms: 100
|
14
|
+
type: RSSecondary
|
15
|
+
tags:
|
16
|
+
data_center: nyc
|
17
|
+
- address: a:27017
|
18
|
+
avg_rtt_ms: 26
|
19
|
+
type: RSPrimary
|
20
|
+
tags:
|
21
|
+
data_center: nyc
|
22
|
+
operation: read
|
23
|
+
read_preference:
|
24
|
+
mode: SecondaryPreferred
|
25
|
+
tag_sets:
|
26
|
+
- data_center: nyc
|
27
|
+
suitable_servers:
|
28
|
+
- *1
|
29
|
+
- *2
|
30
|
+
in_latency_window:
|
31
|
+
- *1
|
@@ -0,0 +1,29 @@
|
|
1
|
+
---
|
2
|
+
topology_description:
|
3
|
+
type: ReplicaSetWithPrimary
|
4
|
+
servers:
|
5
|
+
- address: b:27017
|
6
|
+
avg_rtt_ms: 5
|
7
|
+
type: RSSecondary
|
8
|
+
tags:
|
9
|
+
data_center: nyc
|
10
|
+
- address: c:27017
|
11
|
+
avg_rtt_ms: 100
|
12
|
+
type: RSSecondary
|
13
|
+
tags:
|
14
|
+
data_center: nyc
|
15
|
+
- &1
|
16
|
+
address: a:27017
|
17
|
+
avg_rtt_ms: 26
|
18
|
+
type: RSPrimary
|
19
|
+
tags:
|
20
|
+
data_center: nyc
|
21
|
+
operation: read
|
22
|
+
read_preference:
|
23
|
+
mode: SecondaryPreferred
|
24
|
+
tag_sets:
|
25
|
+
- data_center: sf
|
26
|
+
suitable_servers:
|
27
|
+
- *1
|
28
|
+
in_latency_window:
|
29
|
+
- *1
|
data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
---
|
2
|
+
topology_description:
|
3
|
+
type: ReplicaSetWithPrimary
|
4
|
+
servers:
|
5
|
+
- address: b:27017
|
6
|
+
avg_rtt_ms: 5
|
7
|
+
type: RSSecondary
|
8
|
+
tags:
|
9
|
+
data_center: nyc
|
10
|
+
- address: c:27017
|
11
|
+
avg_rtt_ms: 100
|
12
|
+
type: RSSecondary
|
13
|
+
tags:
|
14
|
+
data_center: nyc
|
15
|
+
- address: a:27017
|
16
|
+
avg_rtt_ms: 26
|
17
|
+
type: RSPrimary
|
18
|
+
tags:
|
19
|
+
data_center: nyc
|
20
|
+
operation: read
|
21
|
+
read_preference:
|
22
|
+
mode: Secondary
|
23
|
+
tag_sets:
|
24
|
+
- data_center: sf
|
25
|
+
suitable_servers: []
|
26
|
+
in_latency_window: []
|
@@ -6,25 +6,19 @@ topology_description:
|
|
6
6
|
address: g:27017
|
7
7
|
avg_rtt_ms: 5
|
8
8
|
type: Mongos
|
9
|
-
|
10
|
-
|
9
|
+
tags:
|
10
|
+
data_center: nyc
|
11
11
|
- &2
|
12
12
|
address: h:27017
|
13
13
|
avg_rtt_ms: 35
|
14
14
|
type: Mongos
|
15
|
-
|
16
|
-
|
15
|
+
tags:
|
16
|
+
data_center: dc
|
17
17
|
operation: read
|
18
18
|
read_preference:
|
19
19
|
mode: SecondaryPreferred
|
20
20
|
tag_sets:
|
21
21
|
- data_center: nyc
|
22
|
-
candidate_servers:
|
23
|
-
- *1
|
24
|
-
- *2
|
25
|
-
eligible_servers:
|
26
|
-
- *1
|
27
|
-
- *2
|
28
22
|
suitable_servers:
|
29
23
|
- *1
|
30
24
|
- *2
|
@@ -6,17 +6,13 @@ topology_description:
|
|
6
6
|
address: a:27017
|
7
7
|
avg_rtt_ms: 5
|
8
8
|
type: Standalone
|
9
|
-
|
10
|
-
|
9
|
+
tags:
|
10
|
+
data_center: dc
|
11
11
|
operation: read
|
12
12
|
read_preference:
|
13
13
|
mode: SecondaryPreferred
|
14
14
|
tag_sets:
|
15
15
|
- data_center: nyc
|
16
|
-
candidate_servers:
|
17
|
-
- *1
|
18
|
-
eligible_servers:
|
19
|
-
- *1
|
20
16
|
suitable_servers:
|
21
17
|
- *1
|
22
18
|
in_latency_window:
|
@@ -2,12 +2,14 @@ shared_examples 'a bulk write object' do
|
|
2
2
|
|
3
3
|
context 'when no operations are provided' do
|
4
4
|
|
5
|
-
let(:operations)
|
5
|
+
let(:operations) do
|
6
|
+
[]
|
7
|
+
end
|
6
8
|
|
7
9
|
it 'raises an error' do
|
8
10
|
expect {
|
9
11
|
bulk.execute
|
10
|
-
}.to raise_error(
|
12
|
+
}.to raise_error(ArgumentError)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
@@ -20,7 +22,7 @@ shared_examples 'a bulk write object' do
|
|
20
22
|
it 'raises an error' do
|
21
23
|
expect {
|
22
24
|
bulk.execute
|
23
|
-
}.to raise_error(Mongo::Error::
|
25
|
+
}.to raise_error(Mongo::Error::InvalidBulkOperationType)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -32,8 +34,8 @@ shared_examples 'a bulk write object' do
|
|
32
34
|
[{ insert_one: { name: 'test' }}]
|
33
35
|
end
|
34
36
|
|
35
|
-
it 'returns
|
36
|
-
expect(bulk.execute[
|
37
|
+
it 'returns n_inserted of 1' do
|
38
|
+
expect(bulk.execute[:n_inserted]).to eq(1)
|
37
39
|
end
|
38
40
|
|
39
41
|
it 'only inserts that document' do
|
@@ -51,7 +53,7 @@ shared_examples 'a bulk write object' do
|
|
51
53
|
it 'raises an exception' do
|
52
54
|
expect {
|
53
55
|
bulk.execute
|
54
|
-
}.to raise_error(Mongo::Error::
|
56
|
+
}.to raise_error(Mongo::Error::InvalidBulkOperation)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -71,7 +73,9 @@ shared_examples 'a bulk write object' do
|
|
71
73
|
end
|
72
74
|
|
73
75
|
let(:operations) do
|
74
|
-
[{ delete_one: { a: 1 }}
|
76
|
+
[ { delete_one: { a: 1 }},
|
77
|
+
{ delete_one: { a: 2 }}
|
78
|
+
]
|
75
79
|
end
|
76
80
|
|
77
81
|
context 'when no selector is specified' do
|
@@ -83,14 +87,14 @@ shared_examples 'a bulk write object' do
|
|
83
87
|
it 'raises an exception' do
|
84
88
|
expect {
|
85
89
|
bulk.execute
|
86
|
-
}.to raise_exception(Mongo::Error::
|
90
|
+
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
87
91
|
end
|
88
92
|
end
|
89
93
|
|
90
94
|
context 'when multiple documents match delete selector' do
|
91
95
|
|
92
|
-
it 'reports
|
93
|
-
expect(bulk.execute[
|
96
|
+
it 'reports n_removed correctly' do
|
97
|
+
expect(bulk.execute[:n_removed]).to eq(1)
|
94
98
|
end
|
95
99
|
|
96
100
|
it 'deletes only matching documents' do
|
@@ -123,7 +127,7 @@ shared_examples 'a bulk write object' do
|
|
123
127
|
it 'raises an exception' do
|
124
128
|
expect {
|
125
129
|
bulk.execute
|
126
|
-
}.to raise_exception(Mongo::Error::
|
130
|
+
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
127
131
|
end
|
128
132
|
end
|
129
133
|
|
@@ -131,8 +135,8 @@ shared_examples 'a bulk write object' do
|
|
131
135
|
|
132
136
|
context 'when multiple documents match delete selector' do
|
133
137
|
|
134
|
-
it 'reports
|
135
|
-
expect(bulk.execute[
|
138
|
+
it 'reports n_removed correctly' do
|
139
|
+
expect(bulk.execute[:n_removed]).to eq(2)
|
136
140
|
end
|
137
141
|
|
138
142
|
it 'deletes all matching documents' do
|
@@ -151,8 +155,8 @@ shared_examples 'a bulk write object' do
|
|
151
155
|
[{ 'a' => 2 }]
|
152
156
|
end
|
153
157
|
|
154
|
-
it 'reports
|
155
|
-
expect(bulk.execute[
|
158
|
+
it 'reports n_removed correctly' do
|
159
|
+
expect(bulk.execute[:n_removed]).to eq(1)
|
156
160
|
end
|
157
161
|
|
158
162
|
it 'deletes all matching documents' do
|
@@ -182,32 +186,41 @@ shared_examples 'a bulk write object' do
|
|
182
186
|
end
|
183
187
|
|
184
188
|
let(:operations) do
|
185
|
-
[{ replace_one:
|
189
|
+
[{ replace_one: { find: { a: 1 },
|
190
|
+
replacement: replacement,
|
191
|
+
upsert: false }
|
192
|
+
}]
|
186
193
|
end
|
187
194
|
|
188
195
|
context 'when a replace document is not specified' do
|
189
196
|
|
190
197
|
let(:operations) do
|
191
|
-
[{ replace_one:
|
198
|
+
[{ replace_one: { find: { a: 1 },
|
199
|
+
replacement: nil,
|
200
|
+
upsert: false }
|
201
|
+
}]
|
192
202
|
end
|
193
203
|
|
194
204
|
it 'raises an exception' do
|
195
205
|
expect {
|
196
206
|
bulk.execute
|
197
|
-
}.to raise_exception(
|
207
|
+
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
198
208
|
end
|
199
209
|
end
|
200
210
|
|
201
211
|
context 'when there are $-operator top-level keys' do
|
202
212
|
|
203
|
-
let(:
|
204
|
-
{
|
213
|
+
let(:operations) do
|
214
|
+
[{ replace_one: { find: { a: 1 },
|
215
|
+
replacement: { :$set => { a: 3 }},
|
216
|
+
upsert: false }
|
217
|
+
}]
|
205
218
|
end
|
206
219
|
|
207
220
|
it 'raises an exception' do
|
208
221
|
expect {
|
209
222
|
bulk.execute
|
210
|
-
}.to raise_exception(Mongo::Error::
|
223
|
+
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
211
224
|
end
|
212
225
|
|
213
226
|
end
|
@@ -219,8 +232,8 @@ shared_examples 'a bulk write object' do
|
|
219
232
|
expect(authorized_collection.find(replacement).count).to eq(1)
|
220
233
|
end
|
221
234
|
|
222
|
-
it 'reports
|
223
|
-
expect(bulk.execute[
|
235
|
+
it 'reports n_matched correctly' do
|
236
|
+
expect(bulk.execute[:n_matched]).to eq(1)
|
224
237
|
end
|
225
238
|
|
226
239
|
it 'only applies the replacement to one matching document' do
|
@@ -231,7 +244,10 @@ shared_examples 'a bulk write object' do
|
|
231
244
|
context 'when upsert is true' do
|
232
245
|
|
233
246
|
let(:operations) do
|
234
|
-
[{ replace_one:
|
247
|
+
[{ replace_one: { find: { a: 4 },
|
248
|
+
replacement: replacement,
|
249
|
+
upsert: true }
|
250
|
+
}]
|
235
251
|
end
|
236
252
|
|
237
253
|
let(:expected) do
|
@@ -243,8 +259,8 @@ shared_examples 'a bulk write object' do
|
|
243
259
|
expect(authorized_collection.find(replacement).count).to eq(1)
|
244
260
|
end
|
245
261
|
|
246
|
-
it 'reports
|
247
|
-
expect(bulk.execute[
|
262
|
+
it 'reports n_matched correctly' do
|
263
|
+
expect(bulk.execute[:n_matched]).to eq(0)
|
248
264
|
end
|
249
265
|
|
250
266
|
it 'does not replace any documents' do
|
@@ -266,7 +282,10 @@ shared_examples 'a bulk write object' do
|
|
266
282
|
end
|
267
283
|
|
268
284
|
let(:operations) do
|
269
|
-
[{ update_one:
|
285
|
+
[{ update_one: { find: { a: 1 },
|
286
|
+
update: update,
|
287
|
+
upsert: false }
|
288
|
+
}]
|
270
289
|
end
|
271
290
|
|
272
291
|
before do
|
@@ -283,10 +302,16 @@ shared_examples 'a bulk write object' do
|
|
283
302
|
[{ update_one: [{ a: 1 }]}]
|
284
303
|
end
|
285
304
|
|
305
|
+
let(:operations) do
|
306
|
+
[{ update_one: { find: { a: 1 },
|
307
|
+
upsert: false }
|
308
|
+
}]
|
309
|
+
end
|
310
|
+
|
286
311
|
it 'raises an exception' do
|
287
312
|
expect {
|
288
313
|
bulk.execute
|
289
|
-
}.to raise_exception(
|
314
|
+
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
290
315
|
end
|
291
316
|
end
|
292
317
|
|
@@ -299,26 +324,26 @@ shared_examples 'a bulk write object' do
|
|
299
324
|
it 'raises an exception' do
|
300
325
|
expect {
|
301
326
|
bulk.execute
|
302
|
-
}.to raise_exception(Mongo::Error::
|
327
|
+
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
303
328
|
end
|
304
329
|
end
|
305
330
|
|
306
331
|
context 'when a valid update document is specified' do
|
307
332
|
|
308
|
-
it 'reports
|
309
|
-
expect(bulk.execute[
|
333
|
+
it 'reports n_modified correctly', if: write_command_enabled? do
|
334
|
+
expect(bulk.execute[:n_modified]).to eq(1)
|
310
335
|
end
|
311
336
|
|
312
|
-
it 'reports
|
313
|
-
expect(bulk.execute[
|
337
|
+
it 'reports n_modified correctly', unless: write_command_enabled? do
|
338
|
+
expect(bulk.execute[:n_modified]).to eq(nil)
|
314
339
|
end
|
315
340
|
|
316
|
-
it 'reports
|
317
|
-
expect(bulk.execute[
|
341
|
+
it 'reports n_upserted correctly' do
|
342
|
+
expect(bulk.execute[:n_upserted]).to eq(0)
|
318
343
|
end
|
319
344
|
|
320
|
-
it 'reports
|
321
|
-
expect(bulk.execute[
|
345
|
+
it 'reports n_matched correctly' do
|
346
|
+
expect(bulk.execute[:n_matched]).to eq(1)
|
322
347
|
end
|
323
348
|
|
324
349
|
it 'applies the correct writes' do
|
@@ -329,27 +354,30 @@ shared_examples 'a bulk write object' do
|
|
329
354
|
context 'when upsert is true' do
|
330
355
|
|
331
356
|
let(:operations) do
|
332
|
-
[{ update_one:
|
357
|
+
[{ update_one: { find: { a: 3 },
|
358
|
+
update: update,
|
359
|
+
upsert: true }
|
360
|
+
}]
|
333
361
|
end
|
334
362
|
|
335
363
|
let(:expected) do
|
336
364
|
[{ 'a' => 1 }, { 'a' => 1 }, { 'a' => 2 }]
|
337
365
|
end
|
338
366
|
|
339
|
-
it 'reports
|
340
|
-
expect(bulk.execute[
|
367
|
+
it 'reports n_modified correctly', if: write_command_enabled? do
|
368
|
+
expect(bulk.execute[:n_modified]).to eq(0)
|
341
369
|
end
|
342
370
|
|
343
|
-
it 'reports
|
344
|
-
expect(bulk.execute[
|
371
|
+
it 'reports n_modified correctly', unless: write_command_enabled? do
|
372
|
+
expect(bulk.execute[:n_modified]).to eq(nil)
|
345
373
|
end
|
346
374
|
|
347
|
-
it 'reports
|
348
|
-
expect(bulk.execute[
|
375
|
+
it 'reports n_upserted correctly' do
|
376
|
+
expect(bulk.execute[:n_upserted]).to eq(1)
|
349
377
|
end
|
350
378
|
|
351
|
-
it 'reports
|
352
|
-
expect(bulk.execute[
|
379
|
+
it 'reports n_matched correctly' do
|
380
|
+
expect(bulk.execute[:n_matched]).to eq(0)
|
353
381
|
end
|
354
382
|
|
355
383
|
it 'applies the correct writes' do
|
@@ -371,7 +399,10 @@ shared_examples 'a bulk write object' do
|
|
371
399
|
end
|
372
400
|
|
373
401
|
let(:operations) do
|
374
|
-
[{ update_many:
|
402
|
+
[{ update_many: { find: { a: 1 },
|
403
|
+
update: update,
|
404
|
+
upsert: false }
|
405
|
+
}]
|
375
406
|
end
|
376
407
|
|
377
408
|
let(:expected) do
|
@@ -385,13 +416,15 @@ shared_examples 'a bulk write object' do
|
|
385
416
|
context 'when an update document is not specified' do
|
386
417
|
|
387
418
|
let(:operations) do
|
388
|
-
[{ update_many:
|
419
|
+
[{ update_many: { find: { a: 1 },
|
420
|
+
upsert: false }
|
421
|
+
}]
|
389
422
|
end
|
390
423
|
|
391
424
|
it 'raises an exception' do
|
392
425
|
expect do
|
393
426
|
bulk.execute
|
394
|
-
end.to raise_exception(
|
427
|
+
end.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
395
428
|
end
|
396
429
|
end
|
397
430
|
|
@@ -404,26 +437,26 @@ shared_examples 'a bulk write object' do
|
|
404
437
|
it 'raises an exception' do
|
405
438
|
expect do
|
406
439
|
bulk.execute
|
407
|
-
end.to raise_exception(Mongo::Error::
|
440
|
+
end.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
408
441
|
end
|
409
442
|
end
|
410
443
|
|
411
444
|
context 'when a valid update document is specified' do
|
412
445
|
|
413
|
-
it 'reports
|
414
|
-
expect(bulk.execute[
|
446
|
+
it 'reports n_modified correctly', if: write_command_enabled? do
|
447
|
+
expect(bulk.execute[:n_modified]).to eq(2)
|
415
448
|
end
|
416
449
|
|
417
|
-
it 'reports
|
418
|
-
expect(bulk.execute[
|
450
|
+
it 'reports n_modified correctly', unless: write_command_enabled? do
|
451
|
+
expect(bulk.execute[:n_modified]).to eq(nil)
|
419
452
|
end
|
420
453
|
|
421
|
-
it 'reports
|
422
|
-
expect(bulk.execute[
|
454
|
+
it 'reports n_upserted correctly' do
|
455
|
+
expect(bulk.execute[:n_upserted]).to eq(0)
|
423
456
|
end
|
424
457
|
|
425
|
-
it 'reports
|
426
|
-
expect(bulk.execute[
|
458
|
+
it 'reports n_matched correctly' do
|
459
|
+
expect(bulk.execute[:n_matched]).to eq(2)
|
427
460
|
end
|
428
461
|
|
429
462
|
it 'applies the correct writes' do
|
@@ -434,27 +467,30 @@ shared_examples 'a bulk write object' do
|
|
434
467
|
context 'when upsert is true' do
|
435
468
|
|
436
469
|
let(:operations) do
|
437
|
-
[{
|
470
|
+
[{ update_many: { find: { a: 3 },
|
471
|
+
update: update,
|
472
|
+
upsert: true }
|
473
|
+
}]
|
438
474
|
end
|
439
475
|
|
440
476
|
let(:expected) do
|
441
477
|
[ { 'a' => 1 }, { 'a' => 1 }, { 'a' => 2 } ]
|
442
478
|
end
|
443
479
|
|
444
|
-
it 'reports
|
445
|
-
expect(bulk.execute[
|
480
|
+
it 'reports n_modified correctly', if: write_command_enabled? do
|
481
|
+
expect(bulk.execute[:n_modified]).to eq(0)
|
446
482
|
end
|
447
483
|
|
448
|
-
it 'reports
|
449
|
-
expect(bulk.execute[
|
484
|
+
it 'reports n_modified correctly', unless: write_command_enabled? do
|
485
|
+
expect(bulk.execute[:n_modified]).to eq(nil)
|
450
486
|
end
|
451
487
|
|
452
|
-
it 'reports
|
453
|
-
expect(bulk.execute[
|
488
|
+
it 'reports n_upserted correctly' do
|
489
|
+
expect(bulk.execute[:n_upserted]).to eq(1)
|
454
490
|
end
|
455
491
|
|
456
|
-
it 'reports
|
457
|
-
expect(bulk.execute[
|
492
|
+
it 'reports n_matched correctly' do
|
493
|
+
expect(bulk.execute[:n_matched]).to eq(0)
|
458
494
|
end
|
459
495
|
|
460
496
|
it 'applies the correct writes' do
|
@@ -468,7 +504,6 @@ shared_examples 'a bulk write object' do
|
|
468
504
|
context 'when the operations need to be split' do
|
469
505
|
|
470
506
|
before do
|
471
|
-
authorized_collection.find.remove_many
|
472
507
|
6000.times do |i|
|
473
508
|
authorized_collection.insert_one(x: i)
|
474
509
|
end
|
@@ -477,14 +512,16 @@ shared_examples 'a bulk write object' do
|
|
477
512
|
let(:operations) do
|
478
513
|
[].tap do |ops|
|
479
514
|
3000.times do |i|
|
480
|
-
ops << { :
|
481
|
-
|
515
|
+
ops << { update_one: { find: { x: i },
|
516
|
+
update: { '$set' => { x: 6000-i } },
|
517
|
+
upsert: false }
|
482
518
|
}
|
483
519
|
end
|
484
520
|
ops << { :insert_one => { test: 'emily' } }
|
485
521
|
3000.times do |i|
|
486
|
-
ops << { :
|
487
|
-
|
522
|
+
ops << { update_one: { find: { x: 3000+i },
|
523
|
+
update: { '$set' => { x: 3000-i } },
|
524
|
+
upsert: false }
|
488
525
|
}
|
489
526
|
end
|
490
527
|
end
|