mongo 2.2.2 → 2.2.3
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 +155 -0
- data/lib/csasl/csasl.bundle +0 -0
- data/lib/mongo/bulk_write/result.rb +1 -1
- data/lib/mongo/bulk_write/result_combiner.rb +8 -5
- data/lib/mongo/cluster/topology/replica_set.rb +2 -1
- data/lib/mongo/error.rb +5 -0
- data/lib/mongo/error/parser.rb +12 -1
- data/lib/mongo/operation/result.rb +2 -2
- data/lib/mongo/operation/write/bulk/delete/result.rb +5 -1
- data/lib/mongo/operation/write/bulk/update/result.rb +38 -7
- data/lib/mongo/protocol/reply.rb +12 -0
- data/lib/mongo/server/description.rb +1 -2
- data/lib/mongo/uri.rb +4 -3
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/bulk_write_spec.rb +648 -21
- data/spec/mongo/cluster/topology/replica_set_spec.rb +2 -0
- data/spec/mongo/operation/result_spec.rb +15 -0
- data/spec/mongo/uri_spec.rb +9 -1
- data/spec/support/sdam/rs/primary_reports_new_member.yml +163 -0
- metadata +6 -5
- metadata.gz.sig +0 -0
- data/spec/support/shared/bulk_write.rb +0 -731
@@ -160,6 +160,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
160
160
|
let(:description) do
|
161
161
|
double('description').tap do |d|
|
162
162
|
allow(d).to receive(:replica_set_member?).and_return(false)
|
163
|
+
allow(d).to receive(:primary?).and_return(false)
|
163
164
|
end
|
164
165
|
end
|
165
166
|
|
@@ -179,6 +180,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
179
180
|
double('description').tap do |d|
|
180
181
|
allow(d).to receive(:replica_set_member?).and_return(true)
|
181
182
|
allow(d).to receive(:replica_set_name).and_return('testing')
|
183
|
+
allow(d).to receive(:primary?).and_return(false)
|
182
184
|
end
|
183
185
|
end
|
184
186
|
|
@@ -208,6 +208,21 @@ describe Mongo::Operation::Result do
|
|
208
208
|
expect(result).to_not be_successful
|
209
209
|
end
|
210
210
|
end
|
211
|
+
|
212
|
+
context 'when the query reply has the cursor_not_found flag set' do
|
213
|
+
|
214
|
+
let(:flags) do
|
215
|
+
[ :cursor_not_found ]
|
216
|
+
end
|
217
|
+
|
218
|
+
let(:documents) do
|
219
|
+
[]
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'returns false' do
|
223
|
+
expect(result).to_not be_successful
|
224
|
+
end
|
225
|
+
end
|
211
226
|
end
|
212
227
|
|
213
228
|
context 'when the reply is for a write command' do
|
data/spec/mongo/uri_spec.rb
CHANGED
@@ -524,11 +524,19 @@ describe 'invalid uris' do
|
|
524
524
|
let(:mechanism) { 'GSSAPI' }
|
525
525
|
let(:expected) { :gssapi }
|
526
526
|
|
527
|
-
|
528
527
|
it 'sets the auth mechanism to :gssapi' do
|
529
528
|
expect(uri.uri_options[:auth_mech]).to eq(expected)
|
530
529
|
end
|
531
530
|
end
|
531
|
+
|
532
|
+
context 'scram-sha-1' do
|
533
|
+
let(:mechanism) { 'SCRAM-SHA-1' }
|
534
|
+
let(:expected) { :scram }
|
535
|
+
|
536
|
+
it 'sets the auth mechanism to :scram' do
|
537
|
+
expect(uri.uri_options[:auth_mech]).to eq(expected)
|
538
|
+
end
|
539
|
+
end
|
532
540
|
end
|
533
541
|
|
534
542
|
context 'auth source provided' do
|
@@ -0,0 +1,163 @@
|
|
1
|
+
description: "Primary reports a new member"
|
2
|
+
|
3
|
+
uri: "mongodb://a/?replicaSet=rs"
|
4
|
+
|
5
|
+
phases: [
|
6
|
+
|
7
|
+
# At first, a is a secondary.
|
8
|
+
{
|
9
|
+
responses: [
|
10
|
+
|
11
|
+
["a:27017", {
|
12
|
+
|
13
|
+
ok: 1,
|
14
|
+
ismaster: false,
|
15
|
+
secondary: true,
|
16
|
+
setName: "rs",
|
17
|
+
hosts: ["a:27017", "b:27017"]
|
18
|
+
}]
|
19
|
+
],
|
20
|
+
|
21
|
+
outcome: {
|
22
|
+
|
23
|
+
servers: {
|
24
|
+
|
25
|
+
"a:27017": {
|
26
|
+
|
27
|
+
type: "RSSecondary",
|
28
|
+
setName: "rs"
|
29
|
+
},
|
30
|
+
|
31
|
+
"b:27017": {
|
32
|
+
|
33
|
+
type: "Unknown",
|
34
|
+
setName:
|
35
|
+
}
|
36
|
+
},
|
37
|
+
|
38
|
+
topologyType: "ReplicaSetNoPrimary",
|
39
|
+
setName: "rs"
|
40
|
+
}
|
41
|
+
},
|
42
|
+
|
43
|
+
# b is the primary.
|
44
|
+
{
|
45
|
+
responses: [
|
46
|
+
|
47
|
+
["b:27017", {
|
48
|
+
|
49
|
+
ok: 1,
|
50
|
+
ismaster: true,
|
51
|
+
setName: "rs",
|
52
|
+
hosts: ["a:27017", "b:27017"]
|
53
|
+
}]
|
54
|
+
],
|
55
|
+
|
56
|
+
outcome: {
|
57
|
+
|
58
|
+
servers: {
|
59
|
+
|
60
|
+
"a:27017": {
|
61
|
+
|
62
|
+
type: "RSSecondary",
|
63
|
+
setName: "rs"
|
64
|
+
},
|
65
|
+
|
66
|
+
"b:27017": {
|
67
|
+
|
68
|
+
type: "RSPrimary",
|
69
|
+
setName: "rs"
|
70
|
+
}
|
71
|
+
},
|
72
|
+
|
73
|
+
topologyType: "ReplicaSetWithPrimary",
|
74
|
+
setName: "rs"
|
75
|
+
}
|
76
|
+
},
|
77
|
+
|
78
|
+
# Admin adds a secondary member c.
|
79
|
+
{
|
80
|
+
responses: [
|
81
|
+
|
82
|
+
["b:27017", {
|
83
|
+
|
84
|
+
ok: 1,
|
85
|
+
ismaster: true,
|
86
|
+
setName: "rs",
|
87
|
+
hosts: ["a:27017", "b:27017", "c:27017"]
|
88
|
+
}]
|
89
|
+
],
|
90
|
+
|
91
|
+
outcome: {
|
92
|
+
|
93
|
+
# c is new.
|
94
|
+
servers: {
|
95
|
+
|
96
|
+
"a:27017": {
|
97
|
+
|
98
|
+
type: "RSSecondary",
|
99
|
+
setName: "rs"
|
100
|
+
},
|
101
|
+
|
102
|
+
"b:27017": {
|
103
|
+
|
104
|
+
type: "RSPrimary",
|
105
|
+
setName: "rs"
|
106
|
+
},
|
107
|
+
|
108
|
+
"c:27017": {
|
109
|
+
|
110
|
+
type: "Unknown",
|
111
|
+
setName:
|
112
|
+
}
|
113
|
+
},
|
114
|
+
|
115
|
+
topologyType: "ReplicaSetWithPrimary",
|
116
|
+
setName: "rs"
|
117
|
+
}
|
118
|
+
},
|
119
|
+
|
120
|
+
# c becomes secondary.
|
121
|
+
{
|
122
|
+
responses: [
|
123
|
+
|
124
|
+
["c:27017", {
|
125
|
+
|
126
|
+
ok: 1,
|
127
|
+
ismaster: false,
|
128
|
+
secondary: true,
|
129
|
+
setName: "rs",
|
130
|
+
primary: "b:27017",
|
131
|
+
hosts: ["a:27017", "b:27017", "c:27017"]
|
132
|
+
}]
|
133
|
+
],
|
134
|
+
|
135
|
+
outcome: {
|
136
|
+
|
137
|
+
# c is a secondary.
|
138
|
+
servers: {
|
139
|
+
|
140
|
+
"a:27017": {
|
141
|
+
|
142
|
+
type: "RSSecondary",
|
143
|
+
setName: "rs"
|
144
|
+
},
|
145
|
+
|
146
|
+
"b:27017": {
|
147
|
+
|
148
|
+
type: "RSPrimary",
|
149
|
+
setName: "rs"
|
150
|
+
},
|
151
|
+
|
152
|
+
"c:27017": {
|
153
|
+
|
154
|
+
type: "RSSecondary",
|
155
|
+
setName: "rs"
|
156
|
+
}
|
157
|
+
},
|
158
|
+
|
159
|
+
topologyType: "ReplicaSetWithPrimary",
|
160
|
+
setName: "rs"
|
161
|
+
}
|
162
|
+
}
|
163
|
+
]
|
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.2.
|
4
|
+
version: 2.2.3
|
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-02-18 00:00:00.000000000 Z
|
36
36
|
dependencies:
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bson
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- README.md
|
60
60
|
- Rakefile
|
61
61
|
- bin/mongo_console
|
62
|
+
- lib/csasl/csasl.bundle
|
62
63
|
- lib/mongo.rb
|
63
64
|
- lib/mongo/address.rb
|
64
65
|
- lib/mongo/address/ipv4.rb
|
@@ -488,6 +489,7 @@ files:
|
|
488
489
|
- spec/support/sdam/rs/primary_disconnect_electionid.yml
|
489
490
|
- spec/support/sdam/rs/primary_disconnect_setversion.yml
|
490
491
|
- spec/support/sdam/rs/primary_mismatched_me.yml
|
492
|
+
- spec/support/sdam/rs/primary_reports_new_member.yml
|
491
493
|
- spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml
|
492
494
|
- spec/support/sdam/rs/primary_wrong_set_name.yml
|
493
495
|
- spec/support/sdam/rs/response_from_removed.yml
|
@@ -548,7 +550,6 @@ files:
|
|
548
550
|
- spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml
|
549
551
|
- spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml
|
550
552
|
- spec/support/server_selection_rtt.rb
|
551
|
-
- spec/support/shared/bulk_write.rb
|
552
553
|
- spec/support/shared/cursor.rb
|
553
554
|
- spec/support/shared/operation.rb
|
554
555
|
- spec/support/shared/protocol.rb
|
@@ -575,7 +576,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
575
576
|
version: '0'
|
576
577
|
requirements: []
|
577
578
|
rubyforge_project:
|
578
|
-
rubygems_version: 2.
|
579
|
+
rubygems_version: 2.4.6
|
579
580
|
signing_key:
|
580
581
|
specification_version: 4
|
581
582
|
summary: Ruby driver for MongoDB
|
@@ -776,6 +777,7 @@ test_files:
|
|
776
777
|
- spec/support/sdam/rs/primary_disconnect_electionid.yml
|
777
778
|
- spec/support/sdam/rs/primary_disconnect_setversion.yml
|
778
779
|
- spec/support/sdam/rs/primary_mismatched_me.yml
|
780
|
+
- spec/support/sdam/rs/primary_reports_new_member.yml
|
779
781
|
- spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml
|
780
782
|
- spec/support/sdam/rs/primary_wrong_set_name.yml
|
781
783
|
- spec/support/sdam/rs/response_from_removed.yml
|
@@ -836,7 +838,6 @@ test_files:
|
|
836
838
|
- spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml
|
837
839
|
- spec/support/server_selection.rb
|
838
840
|
- spec/support/server_selection_rtt.rb
|
839
|
-
- spec/support/shared/bulk_write.rb
|
840
841
|
- spec/support/shared/cursor.rb
|
841
842
|
- spec/support/shared/operation.rb
|
842
843
|
- spec/support/shared/protocol.rb
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,731 +0,0 @@
|
|
1
|
-
shared_examples 'a bulk write object' do
|
2
|
-
|
3
|
-
context 'when no operations are provided' do
|
4
|
-
|
5
|
-
let(:operations) do
|
6
|
-
[]
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'raises an error' do
|
10
|
-
expect {
|
11
|
-
bulk.execute
|
12
|
-
}.to raise_error(ArgumentError)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when invalid operations are provided' do
|
17
|
-
|
18
|
-
let(:operations) do
|
19
|
-
[{ :not_an_op => {}}]
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'raises an error' do
|
23
|
-
expect {
|
24
|
-
bulk.execute
|
25
|
-
}.to raise_error(Mongo::Error::InvalidBulkOperationType)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'when an insert_one operation is provided' do
|
30
|
-
|
31
|
-
context 'when there is a write failure' do
|
32
|
-
|
33
|
-
let(:operations) do
|
34
|
-
[{ insert_one: { _id: 1 }}, { insert_one: { _id: 1 }}]
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'raises a BulkWriteError' do
|
38
|
-
expect {
|
39
|
-
bulk.execute
|
40
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when a document is provided' do
|
45
|
-
|
46
|
-
let(:operations) do
|
47
|
-
[{ insert_one: { name: 'test' }}]
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns n_inserted of 1' do
|
51
|
-
expect(bulk.execute.inserted_count).to eq(1)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'only inserts that document' do
|
55
|
-
bulk.execute
|
56
|
-
expect(authorized_collection.find.first['name']).to eq('test')
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'when there is a write concern error' do
|
60
|
-
|
61
|
-
context 'when the server version is < 2.6' do
|
62
|
-
|
63
|
-
it 'raises a BulkWriteError', if: !write_command_enabled? && standalone? do
|
64
|
-
expect {
|
65
|
-
bulk_invalid_write_concern.execute
|
66
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when the server version has write commands enabled' do
|
71
|
-
|
72
|
-
it 'raises an OperationFailure', if: write_command_enabled? && standalone? do
|
73
|
-
expect {
|
74
|
-
bulk_invalid_write_concern.execute
|
75
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'when an invalid object is provided' do
|
82
|
-
|
83
|
-
let(:operations) do
|
84
|
-
[{ insert_one: [] }]
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'raises an exception' do
|
88
|
-
expect {
|
89
|
-
bulk.execute
|
90
|
-
}.to raise_error(Mongo::Error::InvalidBulkOperation)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'delete_one' do
|
96
|
-
|
97
|
-
let(:docs) do
|
98
|
-
[ { a: 1 }, { a: 1 } ]
|
99
|
-
end
|
100
|
-
|
101
|
-
let(:expected) do
|
102
|
-
[{ 'a' => 1 }]
|
103
|
-
end
|
104
|
-
|
105
|
-
before do
|
106
|
-
authorized_collection.insert_many(docs)
|
107
|
-
end
|
108
|
-
|
109
|
-
let(:operations) do
|
110
|
-
[ { delete_one: { a: 1 }},
|
111
|
-
{ delete_one: { a: 2 }}
|
112
|
-
]
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'when no selector is specified' do
|
116
|
-
|
117
|
-
let(:operations) do
|
118
|
-
[{ delete_one: nil }]
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'raises an exception' do
|
122
|
-
expect {
|
123
|
-
bulk.execute
|
124
|
-
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context 'when multiple documents match delete selector' do
|
129
|
-
|
130
|
-
it 'reports n_removed correctly' do
|
131
|
-
expect(bulk.execute.deleted_count).to eq(1)
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'deletes only matching documents' do
|
135
|
-
bulk.execute
|
136
|
-
expect(authorized_collection.find.projection(_id: 0).to_a).to eq(expected)
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'when there is a write concern error' do
|
140
|
-
|
141
|
-
context 'when the server version is < 2.6' do
|
142
|
-
|
143
|
-
it 'raises a BulkWriteError', if: !write_command_enabled? && standalone? do
|
144
|
-
expect {
|
145
|
-
bulk_invalid_write_concern.execute
|
146
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'when the server version has write commands enabled' do
|
151
|
-
|
152
|
-
it 'raises an OperationFailure', if: write_command_enabled? && standalone? do
|
153
|
-
expect {
|
154
|
-
bulk_invalid_write_concern.execute
|
155
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context 'when a delete_many operation is provided' do
|
163
|
-
|
164
|
-
let(:docs) do
|
165
|
-
[{ a: 1 }, { a: 1 }]
|
166
|
-
end
|
167
|
-
|
168
|
-
before do
|
169
|
-
authorized_collection.insert_many(docs)
|
170
|
-
end
|
171
|
-
|
172
|
-
let(:operations) do
|
173
|
-
[{ delete_many: { a: 1 }}]
|
174
|
-
end
|
175
|
-
|
176
|
-
context 'when no selector is specified' do
|
177
|
-
|
178
|
-
let(:operations) do
|
179
|
-
[{ delete_many: nil }]
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'raises an exception' do
|
183
|
-
expect {
|
184
|
-
bulk.execute
|
185
|
-
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context 'when a selector is specified' do
|
190
|
-
|
191
|
-
context 'when multiple documents match delete selector' do
|
192
|
-
|
193
|
-
it 'reports n_removed correctly' do
|
194
|
-
expect(bulk.execute.deleted_count).to eq(2)
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'deletes all matching documents' do
|
198
|
-
bulk.execute
|
199
|
-
expect(authorized_collection.find.to_a).to be_empty
|
200
|
-
end
|
201
|
-
|
202
|
-
context 'when there is a write concern error' do
|
203
|
-
|
204
|
-
context 'when the server version is < 2.6' do
|
205
|
-
|
206
|
-
it 'raises a BulkWriteError', if: !write_command_enabled? && standalone? do
|
207
|
-
expect {
|
208
|
-
bulk_invalid_write_concern.execute
|
209
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
context 'when the server version has write commands enabled' do
|
214
|
-
|
215
|
-
it 'raises an OperationFailure', if: write_command_enabled? && standalone? do
|
216
|
-
expect {
|
217
|
-
bulk_invalid_write_concern.execute
|
218
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context 'when only one document matches delete selector' do
|
225
|
-
|
226
|
-
let(:docs) do
|
227
|
-
[{ a: 1 }, { a: 2 }]
|
228
|
-
end
|
229
|
-
|
230
|
-
let(:expected) do
|
231
|
-
[{ 'a' => 2 }]
|
232
|
-
end
|
233
|
-
|
234
|
-
it 'reports n_removed correctly' do
|
235
|
-
expect(bulk.execute.deleted_count).to eq(1)
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'deletes all matching documents' do
|
239
|
-
bulk.execute
|
240
|
-
expect(authorized_collection.find.projection(_id: 0).to_a).to eq(expected)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
context 'when a replace_one operation is provided' do
|
247
|
-
|
248
|
-
let(:docs) do
|
249
|
-
[{ a: 1 }, { a: 1 }]
|
250
|
-
end
|
251
|
-
|
252
|
-
let(:expected) do
|
253
|
-
[{ 'a' => 2 }, { 'a' => 1 }]
|
254
|
-
end
|
255
|
-
|
256
|
-
before do
|
257
|
-
authorized_collection.insert_many(docs)
|
258
|
-
end
|
259
|
-
|
260
|
-
let(:replacement) do
|
261
|
-
{ a: 2 }
|
262
|
-
end
|
263
|
-
|
264
|
-
let(:operations) do
|
265
|
-
[{ replace_one: { find: { a: 1 },
|
266
|
-
replacement: replacement,
|
267
|
-
upsert: false }
|
268
|
-
}]
|
269
|
-
end
|
270
|
-
|
271
|
-
context 'when a replace document is not specified' do
|
272
|
-
|
273
|
-
let(:operations) do
|
274
|
-
[{ replace_one: { find: { a: 1 },
|
275
|
-
replacement: nil,
|
276
|
-
upsert: false }
|
277
|
-
}]
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'raises an exception' do
|
281
|
-
expect {
|
282
|
-
bulk.execute
|
283
|
-
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
context 'when there are $-operator top-level keys' do
|
288
|
-
|
289
|
-
let(:operations) do
|
290
|
-
[{ replace_one: { find: { a: 1 },
|
291
|
-
replacement: { :$set => { a: 3 }},
|
292
|
-
upsert: false }
|
293
|
-
}]
|
294
|
-
end
|
295
|
-
|
296
|
-
it 'raises an exception' do
|
297
|
-
expect {
|
298
|
-
bulk.execute
|
299
|
-
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
300
|
-
end
|
301
|
-
|
302
|
-
end
|
303
|
-
|
304
|
-
context 'when a replace document is specified' do
|
305
|
-
|
306
|
-
it 'applies the replacement to only one matching document' do
|
307
|
-
bulk.execute
|
308
|
-
expect(authorized_collection.find(replacement).count).to eq(1)
|
309
|
-
end
|
310
|
-
|
311
|
-
it 'reports n_matched correctly' do
|
312
|
-
expect(bulk.execute.matched_count).to eq(1)
|
313
|
-
end
|
314
|
-
|
315
|
-
it 'only applies the replacement to one matching document' do
|
316
|
-
bulk.execute
|
317
|
-
expect(authorized_collection.find.projection(_id: 0).to_a).to eq(expected)
|
318
|
-
end
|
319
|
-
|
320
|
-
context 'when there is a write concern error' do
|
321
|
-
|
322
|
-
context 'when the server version is < 2.6' do
|
323
|
-
|
324
|
-
it 'raises a BulkWriteError', if: !write_command_enabled? && standalone? do
|
325
|
-
expect {
|
326
|
-
bulk_invalid_write_concern.execute
|
327
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
context 'when the server version has write commands enabled' do
|
332
|
-
|
333
|
-
it 'raises an OperationFailure', if: write_command_enabled? && standalone? do
|
334
|
-
expect {
|
335
|
-
bulk_invalid_write_concern.execute
|
336
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
context 'when upsert is true' do
|
342
|
-
|
343
|
-
let(:operations) do
|
344
|
-
[{ replace_one: { find: { a: 4 },
|
345
|
-
replacement: replacement,
|
346
|
-
upsert: true }
|
347
|
-
}]
|
348
|
-
end
|
349
|
-
|
350
|
-
let(:expected) do
|
351
|
-
[{ 'a' => 1 }, { 'a' => 1 }, { 'a' => 2 }]
|
352
|
-
end
|
353
|
-
|
354
|
-
it 'upserts the replacement document' do
|
355
|
-
bulk.execute
|
356
|
-
expect(authorized_collection.find(replacement).count).to eq(1)
|
357
|
-
end
|
358
|
-
|
359
|
-
it 'reports n_matched correctly' do
|
360
|
-
expect(bulk.execute.matched_count).to eq(0)
|
361
|
-
end
|
362
|
-
|
363
|
-
it 'does not replace any documents' do
|
364
|
-
bulk.execute
|
365
|
-
expect(authorized_collection.find.projection(_id: 0).to_a).to eq(expected)
|
366
|
-
end
|
367
|
-
end
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
context 'when an update_one operation is provided' do
|
372
|
-
|
373
|
-
let(:docs) do
|
374
|
-
[{ a: 1 }, { a: 1 }]
|
375
|
-
end
|
376
|
-
|
377
|
-
let(:update) do
|
378
|
-
{ :$set => { a: 2 }}
|
379
|
-
end
|
380
|
-
|
381
|
-
let(:operations) do
|
382
|
-
[{ update_one: { find: { a: 1 },
|
383
|
-
update: update,
|
384
|
-
upsert: false }
|
385
|
-
}]
|
386
|
-
end
|
387
|
-
|
388
|
-
before do
|
389
|
-
authorized_collection.insert_many(docs)
|
390
|
-
end
|
391
|
-
|
392
|
-
let(:expected) do
|
393
|
-
[{ 'a' => 2 }, { 'a' => 1 }]
|
394
|
-
end
|
395
|
-
|
396
|
-
context 'when there is a write failure' do
|
397
|
-
|
398
|
-
let(:operations) do
|
399
|
-
[{ update_one: { find: { a: 1 },
|
400
|
-
update: { '$st' => { field: 'blah' } },
|
401
|
-
upsert: false }
|
402
|
-
}]
|
403
|
-
end
|
404
|
-
|
405
|
-
it 'raises a BulkWriteError' do
|
406
|
-
expect {
|
407
|
-
bulk.execute
|
408
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
context 'when an update document is not specified' do
|
413
|
-
|
414
|
-
let(:operations) do
|
415
|
-
[{ update_one: [{ a: 1 }]}]
|
416
|
-
end
|
417
|
-
|
418
|
-
let(:operations) do
|
419
|
-
[{ update_one: { find: { a: 1 },
|
420
|
-
upsert: false }
|
421
|
-
}]
|
422
|
-
end
|
423
|
-
|
424
|
-
it 'raises an exception' do
|
425
|
-
expect {
|
426
|
-
bulk.execute
|
427
|
-
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
|
-
context 'when an invalid update document is specified' do
|
432
|
-
|
433
|
-
let(:update) do
|
434
|
-
{ a: 2 }
|
435
|
-
end
|
436
|
-
|
437
|
-
it 'raises an exception' do
|
438
|
-
expect {
|
439
|
-
bulk.execute
|
440
|
-
}.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
441
|
-
end
|
442
|
-
end
|
443
|
-
|
444
|
-
context 'when a valid update document is specified' do
|
445
|
-
|
446
|
-
it 'reports n_modified correctly', if: write_command_enabled? do
|
447
|
-
expect(bulk.execute.modified_count).to eq(1)
|
448
|
-
end
|
449
|
-
|
450
|
-
it 'reports n_modified correctly', unless: write_command_enabled? do
|
451
|
-
expect(bulk.execute.modified_count).to eq(nil)
|
452
|
-
end
|
453
|
-
|
454
|
-
it 'reports n_upserted correctly' do
|
455
|
-
expect(bulk.execute.upserted_count).to eq(0)
|
456
|
-
end
|
457
|
-
|
458
|
-
it 'reports n_matched correctly' do
|
459
|
-
expect(bulk.execute.matched_count).to eq(1)
|
460
|
-
end
|
461
|
-
|
462
|
-
it 'applies the correct writes' do
|
463
|
-
bulk.execute
|
464
|
-
expect(authorized_collection.find.projection(_id: 0).to_a).to eq(expected)
|
465
|
-
end
|
466
|
-
|
467
|
-
context 'when there is a write concern error' do
|
468
|
-
|
469
|
-
context 'when the server version is < 2.6' do
|
470
|
-
|
471
|
-
it 'raises a BulkWriteError', if: !write_command_enabled? && standalone? do
|
472
|
-
expect {
|
473
|
-
bulk_invalid_write_concern.execute
|
474
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
context 'when the server version has write commands enabled' do
|
479
|
-
|
480
|
-
it 'raises an OperationFailure', if: write_command_enabled? && standalone? do
|
481
|
-
expect {
|
482
|
-
bulk_invalid_write_concern.execute
|
483
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
484
|
-
end
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
context 'when upsert is true' do
|
489
|
-
|
490
|
-
let(:operations) do
|
491
|
-
[{ update_one: { find: { a: 3 },
|
492
|
-
update: update,
|
493
|
-
upsert: true }
|
494
|
-
}]
|
495
|
-
end
|
496
|
-
|
497
|
-
let(:expected) do
|
498
|
-
[{ 'a' => 1 }, { 'a' => 1 }, { 'a' => 2 }]
|
499
|
-
end
|
500
|
-
|
501
|
-
it 'reports n_modified correctly', if: write_command_enabled? do
|
502
|
-
expect(bulk.execute.modified_count).to eq(0)
|
503
|
-
end
|
504
|
-
|
505
|
-
it 'reports n_modified correctly', unless: write_command_enabled? do
|
506
|
-
expect(bulk.execute.modified_count).to eq(nil)
|
507
|
-
end
|
508
|
-
|
509
|
-
it 'reports n_upserted correctly' do
|
510
|
-
expect(bulk.execute.upserted_count).to eq(1)
|
511
|
-
end
|
512
|
-
|
513
|
-
it 'returns the upserted ids', if: write_command_enabled? do
|
514
|
-
expect(bulk.execute.upserted_ids.size).to eq(1)
|
515
|
-
end
|
516
|
-
|
517
|
-
it 'reports n_matched correctly' do
|
518
|
-
expect(bulk.execute.matched_count).to eq(0)
|
519
|
-
end
|
520
|
-
|
521
|
-
it 'applies the correct writes' do
|
522
|
-
bulk.execute
|
523
|
-
expect(authorized_collection.find.projection(_id: 0).to_a).to eq(expected)
|
524
|
-
end
|
525
|
-
end
|
526
|
-
end
|
527
|
-
end
|
528
|
-
|
529
|
-
context 'when an update_many operation is provided' do
|
530
|
-
|
531
|
-
let(:docs) do
|
532
|
-
[{ a: 1 }, { a: 1 }]
|
533
|
-
end
|
534
|
-
|
535
|
-
let(:update) do
|
536
|
-
{ :$set => { a: 2 }}
|
537
|
-
end
|
538
|
-
|
539
|
-
let(:operations) do
|
540
|
-
[{ update_many: { find: { a: 1 },
|
541
|
-
update: update,
|
542
|
-
upsert: false }
|
543
|
-
}]
|
544
|
-
end
|
545
|
-
|
546
|
-
let(:expected) do
|
547
|
-
[{ 'a' => 2 }, { 'a' => 2 }]
|
548
|
-
end
|
549
|
-
|
550
|
-
before do
|
551
|
-
authorized_collection.insert_many(docs)
|
552
|
-
end
|
553
|
-
|
554
|
-
context 'when there is a write failure' do
|
555
|
-
|
556
|
-
let(:operations) do
|
557
|
-
[{ update_many: { find: { a: 1 },
|
558
|
-
update: { '$st' => { field: 'blah' } },
|
559
|
-
upsert: false }
|
560
|
-
}]
|
561
|
-
end
|
562
|
-
|
563
|
-
it 'raises an BulkWriteError' do
|
564
|
-
expect {
|
565
|
-
bulk.execute
|
566
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
567
|
-
end
|
568
|
-
end
|
569
|
-
|
570
|
-
context 'when an update document is not specified' do
|
571
|
-
|
572
|
-
let(:operations) do
|
573
|
-
[{ update_many: { find: { a: 1 },
|
574
|
-
upsert: false }
|
575
|
-
}]
|
576
|
-
end
|
577
|
-
|
578
|
-
it 'raises an exception' do
|
579
|
-
expect do
|
580
|
-
bulk.execute
|
581
|
-
end.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
582
|
-
end
|
583
|
-
end
|
584
|
-
|
585
|
-
context 'when an invalid update document is specified' do
|
586
|
-
|
587
|
-
let(:update) do
|
588
|
-
{ a: 2 }
|
589
|
-
end
|
590
|
-
|
591
|
-
it 'raises an exception' do
|
592
|
-
expect do
|
593
|
-
bulk.execute
|
594
|
-
end.to raise_exception(Mongo::Error::InvalidBulkOperation)
|
595
|
-
end
|
596
|
-
end
|
597
|
-
|
598
|
-
context 'when a valid update document is specified' do
|
599
|
-
|
600
|
-
it 'reports n_modified correctly', if: write_command_enabled? do
|
601
|
-
expect(bulk.execute.modified_count).to eq(2)
|
602
|
-
end
|
603
|
-
|
604
|
-
it 'reports n_modified correctly', unless: write_command_enabled? do
|
605
|
-
expect(bulk.execute.modified_count).to eq(nil)
|
606
|
-
end
|
607
|
-
|
608
|
-
it 'reports n_upserted correctly' do
|
609
|
-
expect(bulk.execute.upserted_count).to eq(0)
|
610
|
-
end
|
611
|
-
|
612
|
-
it 'reports n_matched correctly' do
|
613
|
-
expect(bulk.execute.matched_count).to eq(2)
|
614
|
-
end
|
615
|
-
|
616
|
-
it 'applies the correct writes' do
|
617
|
-
bulk.execute
|
618
|
-
expect(authorized_collection.find.projection(_id: 0).to_a).to eq(expected)
|
619
|
-
end
|
620
|
-
|
621
|
-
context 'when there is a write concern error' do
|
622
|
-
|
623
|
-
context 'when the server version is < 2.6' do
|
624
|
-
|
625
|
-
it 'raises a BulkWriteError', if: !write_command_enabled? && standalone? do
|
626
|
-
expect {
|
627
|
-
bulk_invalid_write_concern.execute
|
628
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
629
|
-
end
|
630
|
-
end
|
631
|
-
|
632
|
-
context 'when the server version has write commands enabled' do
|
633
|
-
|
634
|
-
it 'raises an OperationFailure', if: write_command_enabled? && standalone? do
|
635
|
-
expect {
|
636
|
-
bulk_invalid_write_concern.execute
|
637
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
638
|
-
end
|
639
|
-
end
|
640
|
-
end
|
641
|
-
|
642
|
-
context 'when upsert is true' do
|
643
|
-
|
644
|
-
let(:operations) do
|
645
|
-
[{ update_many: { find: { a: 3 },
|
646
|
-
update: update,
|
647
|
-
upsert: true }
|
648
|
-
}]
|
649
|
-
end
|
650
|
-
|
651
|
-
let(:expected) do
|
652
|
-
[ { 'a' => 1 }, { 'a' => 1 }, { 'a' => 2 } ]
|
653
|
-
end
|
654
|
-
|
655
|
-
it 'reports n_modified correctly', if: write_command_enabled? do
|
656
|
-
expect(bulk.execute.modified_count).to eq(0)
|
657
|
-
end
|
658
|
-
|
659
|
-
it 'reports n_modified correctly', unless: write_command_enabled? do
|
660
|
-
expect(bulk.execute.modified_count).to eq(nil)
|
661
|
-
end
|
662
|
-
|
663
|
-
it 'reports n_upserted correctly' do
|
664
|
-
expect(bulk.execute.upserted_count).to eq(1)
|
665
|
-
end
|
666
|
-
|
667
|
-
it 'reports n_matched correctly' do
|
668
|
-
expect(bulk.execute.matched_count).to eq(0)
|
669
|
-
end
|
670
|
-
|
671
|
-
it 'applies the correct writes' do
|
672
|
-
bulk.execute
|
673
|
-
expect(authorized_collection.find.projection(_id: 0).to_a).to eq(expected)
|
674
|
-
end
|
675
|
-
end
|
676
|
-
end
|
677
|
-
end
|
678
|
-
|
679
|
-
context 'when the operations need to be split' do
|
680
|
-
|
681
|
-
before do
|
682
|
-
6000.times do |i|
|
683
|
-
authorized_collection.insert_one(x: i)
|
684
|
-
end
|
685
|
-
end
|
686
|
-
|
687
|
-
let(:operations) do
|
688
|
-
[].tap do |ops|
|
689
|
-
3000.times do |i|
|
690
|
-
ops << { update_one: { find: { x: i },
|
691
|
-
update: { '$set' => { x: 6000-i } },
|
692
|
-
upsert: false }
|
693
|
-
}
|
694
|
-
end
|
695
|
-
ops << { :insert_one => { test: 'emily' } }
|
696
|
-
3000.times do |i|
|
697
|
-
ops << { update_one: { find: { x: 3000+i },
|
698
|
-
update: { '$set' => { x: 3000-i } },
|
699
|
-
upsert: false }
|
700
|
-
}
|
701
|
-
end
|
702
|
-
end
|
703
|
-
end
|
704
|
-
|
705
|
-
it 'completes all operations' do
|
706
|
-
bulk.execute
|
707
|
-
expect(authorized_collection.find(x: { '$lte' => 3000 }).to_a.size).to eq(3000)
|
708
|
-
end
|
709
|
-
|
710
|
-
context 'when there is a write concern error' do
|
711
|
-
|
712
|
-
context 'when the server version is < 2.6' do
|
713
|
-
|
714
|
-
it 'raises a BulkWriteError', if: !write_command_enabled? && standalone? do
|
715
|
-
expect {
|
716
|
-
bulk_invalid_write_concern.execute
|
717
|
-
}.to raise_error(Mongo::Error::BulkWriteError)
|
718
|
-
end
|
719
|
-
end
|
720
|
-
|
721
|
-
context 'when the server version has write commands enabled' do
|
722
|
-
|
723
|
-
it 'raises an OperationFailure', if: write_command_enabled? && standalone? do
|
724
|
-
expect {
|
725
|
-
bulk_invalid_write_concern.execute
|
726
|
-
}.to raise_error(Mongo::Error::OperationFailure)
|
727
|
-
end
|
728
|
-
end
|
729
|
-
end
|
730
|
-
end
|
731
|
-
end
|