mongo 2.0.0.beta → 2.0.0.rc
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 +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/lib/mongo/server.rb
CHANGED
@@ -79,7 +79,7 @@ module Mongo
|
|
79
79
|
# @example Get the server context.
|
80
80
|
# server.context
|
81
81
|
#
|
82
|
-
# @return [ Mongo::Server::Context ] The server context.
|
82
|
+
# @return [ Mongo::Server::Context ] context The server context.
|
83
83
|
#
|
84
84
|
# @since 2.0.0
|
85
85
|
def context
|
@@ -149,7 +149,7 @@ module Mongo
|
|
149
149
|
# @example Are the provided tags a subset of the server's tags.
|
150
150
|
# server.matches_tag_set?({ 'rack' => 'a', 'dc' => 'nyc' })
|
151
151
|
#
|
152
|
-
# @param [ Hash ] The tag set to compare to the server's tags.
|
152
|
+
# @param [ Hash ] tag_set The tag set to compare to the server's tags.
|
153
153
|
#
|
154
154
|
# @return [ true, false ] If the provided tags are a subset of the server's tags.
|
155
155
|
#
|
@@ -84,7 +84,7 @@ module Mongo
|
|
84
84
|
# @example Create the queue.
|
85
85
|
# Mongo::Pool::Queue.new(max_pool_size: 5) { Connection.new }
|
86
86
|
#
|
87
|
-
# @param [
|
87
|
+
# @param [ Hash ] options The options.
|
88
88
|
#
|
89
89
|
# @option options [ Integer ] :max_pool_size The maximum size.
|
90
90
|
# @option options [ Integer ] :min_pool_size The minimum size.
|
@@ -202,7 +202,7 @@ module Mongo
|
|
202
202
|
# @example Instantiate the new description.
|
203
203
|
# Description.new(address, { 'ismaster' => true }, 0.5)
|
204
204
|
#
|
205
|
-
# @param [ Address ]
|
205
|
+
# @param [ Address ] address The server address.
|
206
206
|
# @param [ Hash ] config The result of the ismaster command.
|
207
207
|
# @param [ Float ] average_round_trip_time The moving average time (ms) the ismaster
|
208
208
|
# call took to complete.
|
@@ -69,7 +69,7 @@ module Mongo
|
|
69
69
|
# @example Instantiate the exception.
|
70
70
|
# Mongo::ServerSelector::NoServerAvailable.new(server_selector)
|
71
71
|
#
|
72
|
-
# @
|
72
|
+
# @param [ Hash ] server_selector The server preference that could not be
|
73
73
|
# satisfied.
|
74
74
|
#
|
75
75
|
# @since 2.0.0
|
data/lib/mongo/socket/unix.rb
CHANGED
@@ -47,11 +47,9 @@ module Mongo
|
|
47
47
|
# Initializes a new Unix socket.
|
48
48
|
#
|
49
49
|
# @example Create the Unix socket.
|
50
|
-
# Unix.new('
|
51
|
-
# Unix.new('127.0.0.1', 27017, 30)
|
50
|
+
# Unix.new('/path/to.sock', 27017, 30)
|
52
51
|
#
|
53
|
-
# @param [ String ]
|
54
|
-
# @param [ Integer ] port The port number.
|
52
|
+
# @param [ String ] path The path.
|
55
53
|
# @param [ Float ] timeout The socket timeout value.
|
56
54
|
# @param [ Integer ] family The socket family.
|
57
55
|
#
|
data/lib/mongo/version.rb
CHANGED
@@ -31,7 +31,21 @@ module Mongo
|
|
31
31
|
#
|
32
32
|
# @since 2.0.0
|
33
33
|
def get_last_error
|
34
|
-
@get_last_error ||= { GET_LAST_ERROR => 1 }.merge(
|
34
|
+
@get_last_error ||= { GET_LAST_ERROR => 1 }.merge(
|
35
|
+
Options::Mapper.transform_values_to_strings(options)
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get a human-readable string representation of an acknowledged write concern.
|
40
|
+
#
|
41
|
+
# @example Inspect the write concern.
|
42
|
+
# write_concern.inspect
|
43
|
+
#
|
44
|
+
# @return [ String ] A string representation of an acknowledged write concern.
|
45
|
+
#
|
46
|
+
# @since 2.0.0
|
47
|
+
def inspect
|
48
|
+
"<Mongo::WriteConcern::Acknowledged:0x#{object_id} options=#{options}>"
|
35
49
|
end
|
36
50
|
end
|
37
51
|
end
|
@@ -46,28 +46,6 @@ module Mongo
|
|
46
46
|
def initialize(options)
|
47
47
|
@options = options.freeze
|
48
48
|
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
# Normalizes symbol option values into strings, since symbol will raise
|
53
|
-
# an error on the server side with the gle.
|
54
|
-
#
|
55
|
-
# @api private
|
56
|
-
#
|
57
|
-
# @example Normalize the options.
|
58
|
-
# mode.normalize(:w => :majority)
|
59
|
-
#
|
60
|
-
# @param [ Hash ] options The options to normalize.
|
61
|
-
#
|
62
|
-
# @return [ Hash ] The hash with normalized values.
|
63
|
-
#
|
64
|
-
# @since 2.0.0
|
65
|
-
def normalize(options)
|
66
|
-
options.reduce({}) do |options, (key, value)|
|
67
|
-
options[key] = value.is_a?(Symbol) ? value.to_s : value
|
68
|
-
options
|
69
|
-
end
|
70
|
-
end
|
71
49
|
end
|
72
50
|
end
|
73
51
|
end
|
@@ -38,6 +38,18 @@ module Mongo
|
|
38
38
|
def get_last_error
|
39
39
|
NOOP
|
40
40
|
end
|
41
|
+
|
42
|
+
# Get a human-readable string representation of an unacknowledged write concern.
|
43
|
+
#
|
44
|
+
# @example Inspect the write concern.
|
45
|
+
# write_concern.inspect
|
46
|
+
#
|
47
|
+
# @return [ String ] A string representation of an unacknowledged write concern.
|
48
|
+
#
|
49
|
+
# @since 2.0.0
|
50
|
+
def inspect
|
51
|
+
"<Mongo::WriteConcern::Unacknowledged:0x#{object_id} options=#{options}>"
|
52
|
+
end
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
@@ -3,138 +3,229 @@ require 'spec_helper'
|
|
3
3
|
describe Mongo::BulkWrite do
|
4
4
|
|
5
5
|
before do
|
6
|
-
authorized_collection.find.
|
6
|
+
authorized_collection.find.delete_many
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
after do
|
10
|
+
authorized_collection.find.delete_many
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:bulk) do
|
14
|
+
described_class.get(authorized_collection, operations, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#get' do
|
10
18
|
|
11
|
-
let(:
|
12
|
-
|
19
|
+
let(:operations) do
|
20
|
+
[{ insert_one: { _id: 0 } }]
|
13
21
|
end
|
14
22
|
|
15
|
-
context '
|
23
|
+
context 'When an ordered bulk write object is created' do
|
16
24
|
|
17
25
|
let(:options) do
|
18
26
|
{ ordered: true }
|
19
27
|
end
|
20
28
|
|
21
|
-
|
29
|
+
it 'returns an OrderedBulkWrite object' do
|
30
|
+
expect(bulk).to be_a(Mongo::BulkWrite::OrderedBulkWrite)
|
31
|
+
end
|
32
|
+
end
|
22
33
|
|
23
|
-
|
34
|
+
context 'When an unordered bulk write object is created' do
|
24
35
|
|
25
|
-
|
36
|
+
let(:options) do
|
37
|
+
{ ordered: false }
|
38
|
+
end
|
26
39
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
ex
|
32
|
-
end
|
33
|
-
end
|
40
|
+
it 'returns an UnorderedBulkWrite object' do
|
41
|
+
expect(bulk).to be_a(Mongo::BulkWrite::UnorderedBulkWrite)
|
42
|
+
end
|
43
|
+
end
|
34
44
|
|
35
|
-
|
36
|
-
[].tap do |ops|
|
37
|
-
3000.times do |i|
|
38
|
-
ops << { insert_one: { _id: i } }
|
39
|
-
end
|
40
|
-
ops << { insert_one: { _id: 0 } }
|
41
|
-
ops << { insert_one: { _id: 3001 } }
|
42
|
-
end
|
43
|
-
end
|
45
|
+
context 'When ordered is not specified in options' do
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
let(:options) do
|
48
|
+
{ }
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns an OrderedBulkWrite object' do
|
52
|
+
expect(bulk).to be_a(Mongo::BulkWrite::OrderedBulkWrite)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'Ordered bulk write' do
|
48
58
|
|
49
|
-
|
50
|
-
|
51
|
-
|
59
|
+
let(:options) do
|
60
|
+
{ ordered: true }
|
61
|
+
end
|
62
|
+
|
63
|
+
it_behaves_like 'a bulk write object'
|
64
|
+
|
65
|
+
context 'when the batch requires splitting' do
|
66
|
+
|
67
|
+
context 'when the operations are the same type' do
|
68
|
+
|
69
|
+
let(:error) do
|
70
|
+
begin
|
71
|
+
bulk.execute
|
72
|
+
rescue => ex
|
73
|
+
ex
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:operations) do
|
78
|
+
[].tap do |ops|
|
79
|
+
3000.times do |i|
|
80
|
+
ops << { insert_one: { _id: i } }
|
81
|
+
end
|
82
|
+
ops << { insert_one: { _id: 0 } }
|
83
|
+
ops << { insert_one: { _id: 3001 } }
|
52
84
|
end
|
53
85
|
end
|
86
|
+
|
87
|
+
it 'raises a BulkWriteError' do
|
88
|
+
expect(error).to be_a(Mongo::Error::BulkWriteError)
|
89
|
+
end
|
54
90
|
|
55
|
-
|
91
|
+
it 'halts execution after first error and reports correct index' do
|
92
|
+
expect(error.result[:write_errors].first['index']).to eq(3000)
|
93
|
+
expect(authorized_collection.find.count).to eq(3000)
|
94
|
+
end
|
95
|
+
end
|
56
96
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
97
|
+
context 'when operations are mixed types' do
|
98
|
+
|
99
|
+
let(:error) do
|
100
|
+
begin
|
101
|
+
bulk.execute
|
102
|
+
rescue => ex
|
103
|
+
ex
|
63
104
|
end
|
105
|
+
end
|
64
106
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
ops << { insert_one: { _id: 0 } }
|
71
|
-
ops << { insert_one: { _id: 100 } }
|
107
|
+
let(:operations) do
|
108
|
+
[].tap do |ops|
|
109
|
+
2000.times do |i|
|
110
|
+
ops << { insert_one: { _id: i } }
|
72
111
|
end
|
112
|
+
ops << { delete_one: { _id: 0 } }
|
113
|
+
ops << { insert_one: { _id: 1 } }
|
114
|
+
ops << { insert_one: { _id: 2000 } }
|
73
115
|
end
|
116
|
+
end
|
74
117
|
|
75
|
-
|
76
|
-
|
77
|
-
|
118
|
+
it 'raises a BulkWriteError error' do
|
119
|
+
expect(error).to be_a(Mongo::Error::BulkWriteError)
|
120
|
+
end
|
78
121
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
122
|
+
it 'halts execution after first error and reports correct index' do
|
123
|
+
expect(error.result[:write_errors].first['index']).to eq(2001)
|
124
|
+
expect(authorized_collection.find.count).to eq(1999)
|
83
125
|
end
|
84
126
|
end
|
85
|
-
end
|
86
127
|
|
87
|
-
|
128
|
+
context 'when the operations exceed the max bson size' do
|
88
129
|
|
89
|
-
|
90
|
-
|
130
|
+
let(:error) do
|
131
|
+
begin
|
132
|
+
bulk.execute
|
133
|
+
rescue => ex
|
134
|
+
ex
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
let(:operations) do
|
139
|
+
[].tap do |ops|
|
140
|
+
6.times do |i|
|
141
|
+
ops << { insert_one: { _id: i, x: 'y'*4000000 } }
|
142
|
+
end
|
143
|
+
ops << { insert_one: { _id: 0 } }
|
144
|
+
ops << { insert_one: { _id: 100 } }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'raises a BulkWriteError error' do
|
149
|
+
expect(error).to be_a(Mongo::Error::BulkWriteError)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'splits messages into multiple messages' do
|
153
|
+
error
|
154
|
+
expect(authorized_collection.find.count).to eq(6)
|
155
|
+
end
|
91
156
|
end
|
157
|
+
end
|
158
|
+
end
|
92
159
|
|
93
|
-
|
94
|
-
{ ordered: false }
|
95
|
-
end
|
160
|
+
describe 'Unordered bulk write' do
|
96
161
|
|
97
|
-
|
98
|
-
|
99
|
-
|
162
|
+
let(:options) do
|
163
|
+
{ ordered: false }
|
164
|
+
end
|
100
165
|
|
101
|
-
|
166
|
+
it_behaves_like 'a bulk write object'
|
102
167
|
|
103
|
-
|
168
|
+
context 'when the operations exceed the max batch size' do
|
104
169
|
|
105
|
-
|
170
|
+
context 'when operations are all the same type' do
|
106
171
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
172
|
+
let(:error) do
|
173
|
+
begin
|
174
|
+
bulk.execute
|
175
|
+
rescue => ex
|
176
|
+
ex
|
113
177
|
end
|
178
|
+
end
|
114
179
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
|
-
ops << { insert_one: { _id: 0 } }
|
121
|
-
ops << { insert_one: { _id: 3001 } }
|
180
|
+
let(:operations) do
|
181
|
+
[].tap do |ops|
|
182
|
+
3000.times do |i|
|
183
|
+
ops << { insert_one: { _id: i } }
|
122
184
|
end
|
185
|
+
ops << { insert_one: { _id: 0 } }
|
186
|
+
ops << { insert_one: { _id: 3001 } }
|
123
187
|
end
|
188
|
+
end
|
124
189
|
|
125
|
-
|
126
|
-
|
127
|
-
|
190
|
+
it 'raises a BulkWriteError error' do
|
191
|
+
expect(error).to be_a(Mongo::Error::BulkWriteError)
|
192
|
+
end
|
128
193
|
|
129
|
-
|
130
|
-
|
194
|
+
it 'does not halt execution after first error' do
|
195
|
+
expect(error.result[:write_errors].first['index']).to eq(3000)
|
196
|
+
expect(authorized_collection.find.count).to eq(3001)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'when operations are mixed types' do
|
201
|
+
|
202
|
+
let(:error) do
|
203
|
+
begin
|
204
|
+
bulk.execute
|
205
|
+
rescue => ex
|
206
|
+
ex
|
131
207
|
end
|
208
|
+
end
|
132
209
|
|
133
|
-
|
134
|
-
|
135
|
-
|
210
|
+
let(:operations) do
|
211
|
+
[].tap do |ops|
|
212
|
+
2000.times do |i|
|
213
|
+
ops << { insert_one: { _id: i } }
|
214
|
+
end
|
215
|
+
ops << { delete_one: { _id: 0 } }
|
216
|
+
ops << { insert_one: { _id: 1 } }
|
217
|
+
ops << { insert_one: { _id: 2000 } }
|
136
218
|
end
|
137
219
|
end
|
220
|
+
|
221
|
+
it 'raises a BulkWriteError error' do
|
222
|
+
expect(error).to be_a(Mongo::Error::BulkWriteError)
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'does not halt execution after first error' do
|
226
|
+
expect(error.result[:write_errors].first['index']).to eq(2001)
|
227
|
+
expect(authorized_collection.find.count).to eq(2000)
|
228
|
+
end
|
138
229
|
end
|
139
230
|
|
140
231
|
context 'when the operations exceed the max bson size' do
|
@@ -157,12 +248,8 @@ describe Mongo::BulkWrite do
|
|
157
248
|
end
|
158
249
|
end
|
159
250
|
|
160
|
-
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'raises an error' do
|
165
|
-
expect(error).to be_a(Mongo::Error::BulkWriteFailure)
|
251
|
+
it 'raises a BulkWriteError error' do
|
252
|
+
expect(error).to be_a(Mongo::Error::BulkWriteError)
|
166
253
|
end
|
167
254
|
|
168
255
|
it 'splits messages into multiple messages' do
|