mongo 2.1.0.beta → 2.1.0.rc0
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 +2 -2
- data/lib/mongo.rb +2 -3
- data/lib/mongo/address.rb +7 -5
- data/lib/mongo/address/unix.rb +2 -2
- data/lib/mongo/auth/ldap/conversation.rb +6 -2
- data/lib/mongo/auth/scram/conversation.rb +8 -2
- data/lib/mongo/auth/user/view.rb +21 -0
- data/lib/mongo/bulk_write.rb +155 -23
- data/lib/mongo/bulk_write/combineable.rb +51 -0
- data/lib/mongo/bulk_write/ordered_combiner.rb +55 -0
- data/lib/mongo/bulk_write/result.rb +61 -8
- data/lib/mongo/bulk_write/result_combiner.rb +117 -0
- data/lib/mongo/bulk_write/transformable.rb +117 -0
- data/lib/mongo/bulk_write/unordered_combiner.rb +52 -0
- data/lib/mongo/bulk_write/validatable.rb +62 -0
- data/lib/mongo/client.rb +7 -3
- data/lib/mongo/cluster.rb +3 -3
- data/lib/mongo/cluster/topology/replica_set.rb +8 -6
- data/lib/mongo/cluster/topology/unknown.rb +5 -2
- data/lib/mongo/collection.rb +75 -4
- data/lib/mongo/collection/view.rb +1 -2
- data/lib/mongo/collection/view/aggregation.rb +13 -8
- data/lib/mongo/collection/view/immutable.rb +6 -6
- data/lib/mongo/collection/view/iterable.rb +13 -4
- data/lib/mongo/collection/view/map_reduce.rb +22 -17
- data/lib/mongo/collection/view/readable.rb +121 -70
- data/lib/mongo/cursor.rb +5 -1
- data/lib/mongo/database.rb +3 -3
- data/lib/mongo/database/view.rb +1 -1
- data/lib/mongo/error.rb +7 -0
- data/lib/mongo/{bulk_write/unordered_bulk_write.rb → error/closed_stream.rb} +12 -21
- data/lib/mongo/{bulk_write/ordered_bulk_write.rb → error/extra_file_chunk.rb} +13 -27
- data/lib/mongo/error/file_not_found.rb +37 -0
- data/lib/mongo/error/invalid_file.rb +2 -2
- data/lib/mongo/error/invalid_file_revision.rb +37 -0
- data/lib/mongo/error/invalid_uri.rb +5 -4
- data/lib/mongo/error/missing_file_chunk.rb +38 -0
- data/lib/mongo/error/operation_failure.rb +1 -1
- data/lib/mongo/error/unchangeable_collection_option.rb +38 -0
- data/lib/mongo/error/unexpected_chunk_length.rb +39 -0
- data/lib/mongo/grid.rb +2 -1
- data/lib/mongo/grid/file.rb +12 -9
- data/lib/mongo/grid/file/chunk.rb +6 -6
- data/lib/mongo/grid/file/{metadata.rb → info.rb} +41 -39
- data/lib/mongo/grid/fs_bucket.rb +441 -0
- data/lib/mongo/grid/stream.rb +64 -0
- data/lib/mongo/grid/stream/read.rb +208 -0
- data/lib/mongo/grid/stream/write.rb +187 -0
- data/lib/mongo/index/view.rb +1 -1
- data/lib/mongo/loggable.rb +34 -57
- data/lib/mongo/logger.rb +16 -78
- data/lib/mongo/monitoring.rb +1 -5
- data/lib/mongo/monitoring/command_log_subscriber.rb +35 -17
- data/lib/mongo/monitoring/event/command_succeeded.rb +20 -1
- data/lib/mongo/monitoring/publishable.rb +22 -12
- data/lib/mongo/operation.rb +3 -6
- data/lib/mongo/operation/commands.rb +24 -0
- data/lib/mongo/operation/{aggregate.rb → commands/aggregate.rb} +3 -41
- data/lib/mongo/operation/{aggregate → commands/aggregate}/result.rb +0 -0
- data/lib/mongo/operation/commands/collections_info.rb +66 -0
- data/lib/mongo/operation/{command.rb → commands/command.rb} +2 -18
- data/lib/mongo/operation/commands/indexes.rb +70 -0
- data/lib/mongo/operation/commands/list_collections.rb +54 -0
- data/lib/mongo/operation/commands/list_collections/result.rb +112 -0
- data/lib/mongo/operation/commands/list_indexes.rb +56 -0
- data/lib/mongo/operation/commands/list_indexes/result.rb +115 -0
- data/lib/mongo/operation/{map_reduce.rb → commands/map_reduce.rb} +3 -41
- data/lib/mongo/operation/{map_reduce → commands/map_reduce}/result.rb +0 -0
- data/lib/mongo/operation/{parallel_scan.rb → commands/parallel_scan.rb} +3 -23
- data/lib/mongo/operation/{parallel_scan → commands/parallel_scan}/result.rb +0 -0
- data/lib/mongo/operation/commands/user_query.rb +69 -0
- data/lib/mongo/operation/commands/users_info.rb +53 -0
- data/lib/mongo/operation/commands/users_info/result.rb +36 -0
- data/lib/mongo/operation/executable.rb +4 -68
- data/lib/mongo/operation/kill_cursors.rb +3 -3
- data/lib/mongo/operation/read.rb +0 -4
- data/lib/mongo/operation/read/get_more.rb +2 -22
- data/lib/mongo/operation/read/query.rb +2 -21
- data/lib/mongo/operation/{read_preferrable.rb → read_preference.rb} +3 -2
- data/lib/mongo/operation/specifiable.rb +24 -0
- data/lib/mongo/operation/write.rb +2 -0
- data/lib/mongo/operation/write/bulk.rb +6 -3
- data/lib/mongo/operation/write/bulk/bulkable.rb +82 -0
- data/lib/mongo/operation/write/bulk/delete.rb +71 -0
- data/lib/mongo/operation/write/bulk/delete/result.rb +74 -0
- data/lib/mongo/operation/write/bulk/insert.rb +96 -0
- data/lib/mongo/operation/write/bulk/insert/result.rb +129 -0
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +87 -0
- data/lib/mongo/operation/write/bulk/mergable.rb +71 -0
- data/lib/mongo/operation/write/bulk/update.rb +81 -0
- data/lib/mongo/operation/write/bulk/update/result.rb +174 -0
- data/lib/mongo/operation/write/command/create_index.rb +0 -1
- data/lib/mongo/operation/write/command/create_user.rb +0 -1
- data/lib/mongo/operation/write/command/delete.rb +0 -1
- data/lib/mongo/operation/write/command/drop_index.rb +0 -1
- data/lib/mongo/operation/write/command/insert.rb +0 -1
- data/lib/mongo/operation/write/command/remove_user.rb +0 -1
- data/lib/mongo/operation/write/command/update.rb +0 -1
- data/lib/mongo/operation/write/command/update_user.rb +0 -1
- data/lib/mongo/operation/write/command/writable.rb +13 -18
- data/lib/mongo/operation/write/create_index.rb +4 -27
- data/lib/mongo/operation/write/create_user.rb +4 -30
- data/lib/mongo/operation/write/delete.rb +5 -28
- data/lib/mongo/operation/write/drop_index.rb +3 -3
- data/lib/mongo/operation/write/gle.rb +48 -0
- data/lib/mongo/operation/write/idable.rb +5 -0
- data/lib/mongo/operation/write/insert.rb +2 -24
- data/lib/mongo/operation/write/remove_user.rb +4 -27
- data/lib/mongo/operation/write/update.rb +4 -32
- data/lib/mongo/operation/write/update_user.rb +4 -30
- data/lib/mongo/operation/write/write_command_enabled.rb +53 -0
- data/lib/mongo/options/mapper.rb +4 -2
- data/lib/mongo/protocol/delete.rb +68 -3
- data/lib/mongo/protocol/get_more.rb +54 -2
- data/lib/mongo/protocol/insert.rb +59 -1
- data/lib/mongo/protocol/kill_cursors.rb +53 -4
- data/lib/mongo/protocol/message.rb +12 -12
- data/lib/mongo/protocol/query.rb +139 -65
- data/lib/mongo/protocol/reply.rb +69 -1
- data/lib/mongo/protocol/update.rb +70 -1
- data/lib/mongo/server/connection.rb +11 -3
- data/lib/mongo/server/description.rb +29 -0
- data/lib/mongo/server/description/features.rb +2 -1
- data/lib/mongo/server/monitor.rb +2 -2
- data/lib/mongo/server_selector.rb +14 -10
- data/lib/mongo/server_selector/selectable.rb +24 -22
- data/lib/mongo/socket.rb +6 -3
- data/lib/mongo/socket/tcp.rb +2 -2
- data/lib/mongo/socket/unix.rb +5 -8
- data/lib/mongo/uri.rb +243 -139
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/address/unix_spec.rb +1 -1
- data/spec/mongo/address_spec.rb +25 -0
- data/spec/mongo/auth/ldap/conversation_spec.rb +43 -0
- data/spec/mongo/auth/user/view_spec.rb +26 -1
- data/spec/mongo/bulk_write/ordered_combiner_spec.rb +271 -0
- data/spec/mongo/bulk_write/unordered_combiner_spec.rb +239 -0
- data/spec/mongo/bulk_write_spec.rb +332 -166
- data/spec/mongo/client_spec.rb +25 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +2 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +65 -0
- data/spec/mongo/collection/view/immutable_spec.rb +103 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +98 -3
- data/spec/mongo/collection/view/readable_spec.rb +17 -30
- data/spec/mongo/collection/view_spec.rb +233 -7
- data/spec/mongo/collection_spec.rb +360 -18
- data/spec/mongo/command_monitoring_spec.rb +51 -0
- data/spec/mongo/connection_string_spec.rb +137 -0
- data/spec/mongo/database_spec.rb +27 -11
- data/spec/mongo/grid/file/chunk_spec.rb +5 -5
- data/spec/mongo/grid/file/{metadata_spec.rb → info_spec.rb} +29 -17
- data/spec/mongo/grid/file_spec.rb +8 -8
- data/spec/mongo/grid/fs_bucket_spec.rb +1020 -0
- data/spec/mongo/grid/stream/read_spec.rb +275 -0
- data/spec/mongo/grid/stream/write_spec.rb +440 -0
- data/spec/mongo/grid/stream_spec.rb +48 -0
- data/spec/mongo/gridfs_spec.rb +50 -0
- data/spec/mongo/logger_spec.rb +0 -40
- data/spec/mongo/monitoring/command_log_subscriber_spec.rb +76 -0
- data/spec/mongo/operation/{aggregate_spec.rb → commands/aggregate_spec.rb} +0 -42
- data/spec/mongo/operation/{read → commands}/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/{command_spec.rb → commands/command_spec.rb} +0 -0
- data/spec/mongo/operation/{read → commands}/indexes_spec.rb +1 -1
- data/spec/mongo/operation/{map_reduce_spec.rb → commands/map_reduce_spec.rb} +0 -18
- data/spec/mongo/operation/kill_cursors_spec.rb +1 -1
- data/spec/mongo/operation/{read_preferrable_spec.rb → read_preference_spec.rb} +11 -11
- data/spec/mongo/operation/write/bulk/{bulk_delete_spec.rb → delete_spec.rb} +1 -12
- data/spec/mongo/operation/write/bulk/{bulk_insert_spec.rb → insert_spec.rb} +1 -12
- data/spec/mongo/operation/write/bulk/{bulk_update_spec.rb → update_spec.rb} +1 -12
- data/spec/mongo/operation/write/insert_spec.rb +0 -11
- data/spec/mongo/protocol/kill_cursors_spec.rb +5 -3
- data/spec/mongo/server/description_spec.rb +42 -0
- data/spec/mongo/server/monitor_spec.rb +21 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +1 -0
- data/spec/mongo/server_selection_spec.rb +3 -3
- data/spec/mongo/server_selector/nearest_spec.rb +34 -27
- data/spec/mongo/server_selector/primary_preferred_spec.rb +31 -30
- data/spec/mongo/server_selector/primary_spec.rb +14 -13
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +27 -26
- data/spec/mongo/server_selector/secondary_spec.rb +23 -22
- data/spec/mongo/server_selector_spec.rb +87 -24
- data/spec/mongo/socket/unix_spec.rb +52 -0
- data/spec/mongo/uri_spec.rb +251 -39
- data/spec/spec_helper.rb +11 -4
- data/spec/support/authorization.rb +4 -5
- data/spec/support/command_monitoring.rb +365 -0
- data/spec/support/command_monitoring/bulkWrite.yml +73 -0
- data/spec/support/command_monitoring/command.yml +42 -0
- data/spec/support/command_monitoring/deleteMany.yml +55 -0
- data/spec/support/command_monitoring/deleteOne.yml +55 -0
- data/spec/support/command_monitoring/find.yml +219 -0
- data/spec/support/command_monitoring/insertMany.yml +81 -0
- data/spec/support/command_monitoring/insertOne.yml +51 -0
- data/spec/support/command_monitoring/updateMany.yml +67 -0
- data/spec/support/command_monitoring/updateOne.yml +95 -0
- data/spec/support/connection_string.rb +228 -0
- data/spec/support/connection_string_tests/invalid-uris.yml +193 -0
- data/spec/support/connection_string_tests/valid-auth.yml +256 -0
- data/spec/support/connection_string_tests/valid-host_identifiers.yml +121 -0
- data/spec/support/connection_string_tests/valid-options.yml +30 -0
- data/spec/support/connection_string_tests/valid-unix_socket-absolute.yml +197 -0
- data/spec/support/connection_string_tests/valid-unix_socket-relative.yml +213 -0
- data/spec/support/connection_string_tests/valid-warnings.yml +55 -0
- data/spec/support/crud.rb +3 -1
- data/spec/support/crud/read.rb +14 -10
- data/spec/support/crud/write.rb +36 -9
- data/spec/support/gridfs.rb +637 -0
- data/spec/support/gridfs_tests/delete.yml +157 -0
- data/spec/support/gridfs_tests/download.yml +210 -0
- data/spec/support/gridfs_tests/download_by_name.yml +113 -0
- data/spec/support/gridfs_tests/upload.yml +158 -0
- data/spec/support/sdam/rs/equal_electionids.yml +1 -2
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +0 -3
- data/spec/support/sdam/rs/primary_mismatched_me.yml +37 -0
- data/spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml +75 -0
- data/spec/support/sdam/rs/secondary_mismatched_me.yml +37 -0
- data/spec/support/sdam/single/direct_connection_rsarbiter.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rsprimary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rssecondary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_slave.yml +1 -1
- data/spec/support/sdam/single/direct_connection_standalone.yml +1 -1
- data/spec/support/sdam/single/not_ok_response.yml +0 -1
- data/spec/support/server_discovery_and_monitoring.rb +3 -1
- data/spec/support/server_selection.rb +3 -1
- data/spec/support/shared/bulk_write.rb +192 -0
- data/spec/support/shared/server_selector.rb +21 -12
- metadata +147 -57
- metadata.gz.sig +0 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +0 -252
- data/lib/mongo/bulk_write/deletable.rb +0 -57
- data/lib/mongo/bulk_write/insertable.rb +0 -49
- data/lib/mongo/bulk_write/replacable.rb +0 -58
- data/lib/mongo/bulk_write/updatable.rb +0 -69
- data/lib/mongo/grid/fs.rb +0 -146
- data/lib/mongo/operation/list_collections/result.rb +0 -114
- data/lib/mongo/operation/list_indexes/result.rb +0 -118
- data/lib/mongo/operation/read/collections_info.rb +0 -68
- data/lib/mongo/operation/read/indexes.rb +0 -69
- data/lib/mongo/operation/read/list_collections.rb +0 -76
- data/lib/mongo/operation/read/list_indexes.rb +0 -78
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +0 -145
- data/lib/mongo/operation/write/bulk/bulk_delete/result.rb +0 -75
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +0 -132
- data/lib/mongo/operation/write/bulk/bulk_insert/result.rb +0 -130
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +0 -67
- data/lib/mongo/operation/write/bulk/bulk_update.rb +0 -154
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +0 -174
- data/lib/mongo/operation/write/bulk/legacy_bulk_mergable.rb +0 -83
- data/spec/mongo/grid/fs_spec.rb +0 -160
- data/spec/mongo/loggable_spec.rb +0 -63
@@ -6,6 +6,10 @@ describe Mongo::Collection do
|
|
6
6
|
authorized_collection.delete_many
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:collection_invalid_write_concern) do
|
10
|
+
authorized_collection.client.with(write: { w: (WRITE_CONCERN[:w] + 1) })[authorized_collection.name]
|
11
|
+
end
|
12
|
+
|
9
13
|
describe '#==' do
|
10
14
|
|
11
15
|
let(:database) do
|
@@ -86,6 +90,172 @@ describe Mongo::Collection do
|
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
93
|
+
describe '#with' do
|
94
|
+
|
95
|
+
let(:client) do
|
96
|
+
Mongo::Client.new(ADDRESSES)
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:database) do
|
100
|
+
Mongo::Database.new(client, :test)
|
101
|
+
end
|
102
|
+
|
103
|
+
let(:collection) do
|
104
|
+
database.collection(:users)
|
105
|
+
end
|
106
|
+
|
107
|
+
let(:new_collection) do
|
108
|
+
collection.with(new_options)
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when new read options are provided' do
|
112
|
+
|
113
|
+
let(:new_options) do
|
114
|
+
{ read: { mode: :secondary } }
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'returns a new collection' do
|
118
|
+
expect(new_collection).not_to be(collection)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'sets the new read options on the new collection' do
|
122
|
+
expect(new_collection.read_preference).to eq(Mongo::ServerSelector.get(new_options[:read]))
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'when the client has a server selection timeout setting' do
|
126
|
+
|
127
|
+
let(:client) do
|
128
|
+
Mongo::Client.new(ADDRESSES, server_selection_timeout: 2)
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:server_selection_timeout) do
|
132
|
+
new_collection.read_preference.server_selection_timeout
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'keeps the server_selection_timeout setting from client' do
|
136
|
+
expect(server_selection_timeout).to eq(client.options[:server_selection_timeout])
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'when the client has a read preference set' do
|
141
|
+
|
142
|
+
let(:client) do
|
143
|
+
Mongo::Client.new(ADDRESSES, read: { mode: :primary_preferred })
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'sets the new read options on the new collection' do
|
147
|
+
expect(new_collection.read_preference).to eq(Mongo::ServerSelector.get(new_options[:read]))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'when the client has a read preference and server selection timeout set' do
|
152
|
+
|
153
|
+
let(:client) do
|
154
|
+
Mongo::Client.new(ADDRESSES, read: { mode: :primary_preferred }, server_selection_timeout: 2)
|
155
|
+
end
|
156
|
+
|
157
|
+
let(:server_selection_timeout) do
|
158
|
+
new_collection.read_preference.server_selection_timeout
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'sets the new read options on the new collection' do
|
162
|
+
expect(new_collection.read_preference).to eq(Mongo::ServerSelector.get(new_options[:read]))
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'keeps the server_selection_timeout setting from client' do
|
166
|
+
expect(server_selection_timeout).to eq(client.options[:server_selection_timeout])
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'when new write options are provided' do
|
172
|
+
|
173
|
+
let(:new_options) do
|
174
|
+
{ write: { w: 5 } }
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'returns a new collection' do
|
178
|
+
expect(new_collection).not_to be(collection)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'sets the new write options on the new collection' do
|
182
|
+
expect(new_collection.write_concern.options).to eq(Mongo::WriteConcern.get(new_options[:write]).options)
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when the client has a write concern set' do
|
186
|
+
|
187
|
+
let(:client) do
|
188
|
+
Mongo::Client.new(ADDRESSES, write: { w: 10 })
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'sets the new write options on the new collection' do
|
192
|
+
expect(new_collection.write_concern.options).to eq(Mongo::WriteConcern.get(new_options[:write]).options)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when new read and write options are provided' do
|
198
|
+
|
199
|
+
let(:new_options) do
|
200
|
+
{
|
201
|
+
read: { mode: :secondary },
|
202
|
+
write: { w: 4}
|
203
|
+
}
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'returns a new collection' do
|
207
|
+
expect(new_collection).not_to be(collection)
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'sets the new read options on the new collection' do
|
211
|
+
expect(new_collection.read_preference).to eq(Mongo::ServerSelector.get(new_options[:read]))
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'sets the new write options on the new collection' do
|
215
|
+
expect(new_collection.write_concern.options).to eq(Mongo::WriteConcern.get(new_options[:write]).options)
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'when the client has a server selection timeout setting' do
|
219
|
+
|
220
|
+
let(:client) do
|
221
|
+
Mongo::Client.new(ADDRESSES, server_selection_timeout: 2)
|
222
|
+
end
|
223
|
+
|
224
|
+
let(:server_selection_timeout) do
|
225
|
+
new_collection.read_preference.server_selection_timeout
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'keeps the server_selection_timeout setting from client' do
|
229
|
+
expect(server_selection_timeout).to eq(client.options[:server_selection_timeout])
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context 'when the client has a read preference set' do
|
234
|
+
|
235
|
+
let(:client) do
|
236
|
+
Mongo::Client.new(ADDRESSES, read: { mode: :primary_preferred })
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'sets the new read options on the new collection' do
|
240
|
+
expect(new_collection.read_preference).to eq(Mongo::ServerSelector.get(new_options[:read]))
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
context 'when neither read nor write options are provided' do
|
246
|
+
|
247
|
+
let(:new_options) do
|
248
|
+
{ some_option: 'invalid' }
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'raises an error' do
|
252
|
+
expect {
|
253
|
+
new_collection
|
254
|
+
}.to raise_exception(Mongo::Error::UnchangeableCollectionOption)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
89
259
|
describe '#capped?' do
|
90
260
|
|
91
261
|
let(:database) do
|
@@ -324,7 +494,7 @@ describe Mongo::Collection do
|
|
324
494
|
end
|
325
495
|
|
326
496
|
it 'returns a view with :batch_size set' do
|
327
|
-
expect(view.options[:batch_size]).to
|
497
|
+
expect(view.options[:batch_size]).to eq(options[:batch_size])
|
328
498
|
end
|
329
499
|
end
|
330
500
|
|
@@ -335,7 +505,7 @@ describe Mongo::Collection do
|
|
335
505
|
end
|
336
506
|
|
337
507
|
it 'returns a view with :comment set' do
|
338
|
-
expect(view.
|
508
|
+
expect(view.modifiers[:$comment]).to eq(options[:comment])
|
339
509
|
end
|
340
510
|
end
|
341
511
|
|
@@ -346,10 +516,12 @@ describe Mongo::Collection do
|
|
346
516
|
end
|
347
517
|
|
348
518
|
it 'returns a view with :cursor_type set' do
|
349
|
-
expect(view.options[:cursor_type]).to
|
519
|
+
expect(view.options[:cursor_type]).to eq(options[:cursor_type])
|
350
520
|
end
|
351
521
|
end
|
352
522
|
|
523
|
+
#limit
|
524
|
+
|
353
525
|
context 'when provided :max_time_ms' do
|
354
526
|
|
355
527
|
let(:options) do
|
@@ -357,7 +529,7 @@ describe Mongo::Collection do
|
|
357
529
|
end
|
358
530
|
|
359
531
|
it 'returns a view with :max_time_ms set' do
|
360
|
-
expect(view.
|
532
|
+
expect(view.modifiers[:$maxTimeMS]).to eq(options[:max_time_ms])
|
361
533
|
end
|
362
534
|
end
|
363
535
|
|
@@ -368,7 +540,11 @@ describe Mongo::Collection do
|
|
368
540
|
end
|
369
541
|
|
370
542
|
it 'returns a view with modifiers set' do
|
371
|
-
expect(view.
|
543
|
+
expect(view.modifiers).to eq(options[:modifiers])
|
544
|
+
end
|
545
|
+
|
546
|
+
it 'dups the modifiers hash' do
|
547
|
+
expect(view.modifiers).not_to be(options[:modifiers])
|
372
548
|
end
|
373
549
|
end
|
374
550
|
|
@@ -379,7 +555,7 @@ describe Mongo::Collection do
|
|
379
555
|
end
|
380
556
|
|
381
557
|
it 'returns a view with :no_cursor_timeout set' do
|
382
|
-
expect(view.options[:no_cursor_timeout]).to
|
558
|
+
expect(view.options[:no_cursor_timeout]).to eq(options[:no_cursor_timeout])
|
383
559
|
end
|
384
560
|
end
|
385
561
|
|
@@ -390,7 +566,7 @@ describe Mongo::Collection do
|
|
390
566
|
end
|
391
567
|
|
392
568
|
it 'returns a view with :oplog_replay set' do
|
393
|
-
expect(view.options[:oplog_replay]).to
|
569
|
+
expect(view.options[:oplog_replay]).to eq(options[:oplog_replay])
|
394
570
|
end
|
395
571
|
end
|
396
572
|
|
@@ -401,7 +577,7 @@ describe Mongo::Collection do
|
|
401
577
|
end
|
402
578
|
|
403
579
|
it 'returns a view with :projection set' do
|
404
|
-
expect(view.options[:projection]).to
|
580
|
+
expect(view.options[:projection]).to eq(options[:projection])
|
405
581
|
end
|
406
582
|
end
|
407
583
|
|
@@ -412,7 +588,7 @@ describe Mongo::Collection do
|
|
412
588
|
end
|
413
589
|
|
414
590
|
it 'returns a view with :skip set' do
|
415
|
-
expect(view.options[:skip]).to
|
591
|
+
expect(view.options[:skip]).to eq(options[:skip])
|
416
592
|
end
|
417
593
|
end
|
418
594
|
|
@@ -423,7 +599,7 @@ describe Mongo::Collection do
|
|
423
599
|
end
|
424
600
|
|
425
601
|
it 'returns a view with :sort set' do
|
426
|
-
expect(view.
|
602
|
+
expect(view.modifiers[:$orderby]).to eq(options[:sort])
|
427
603
|
end
|
428
604
|
end
|
429
605
|
end
|
@@ -446,6 +622,19 @@ describe Mongo::Collection do
|
|
446
622
|
it 'contains the ids in the result' do
|
447
623
|
expect(result.inserted_ids.size).to eq(2)
|
448
624
|
end
|
625
|
+
|
626
|
+
context 'when the inserts fail' do
|
627
|
+
|
628
|
+
let(:result) do
|
629
|
+
authorized_collection.insert_many([{ _id: 1 }, { _id: 1 }])
|
630
|
+
end
|
631
|
+
|
632
|
+
it 'raises an BulkWriteError' do
|
633
|
+
expect {
|
634
|
+
result
|
635
|
+
}.to raise_exception(Mongo::Error::BulkWriteError)
|
636
|
+
end
|
637
|
+
end
|
449
638
|
end
|
450
639
|
|
451
640
|
describe '#insert_one' do
|
@@ -469,6 +658,20 @@ describe Mongo::Collection do
|
|
469
658
|
it 'contains the id in the result' do
|
470
659
|
expect(result.inserted_id).to_not be_nil
|
471
660
|
end
|
661
|
+
|
662
|
+
context 'when the insert fails' do
|
663
|
+
|
664
|
+
let(:result) do
|
665
|
+
authorized_collection.insert_one(_id: 1)
|
666
|
+
authorized_collection.insert_one(_id: 1)
|
667
|
+
end
|
668
|
+
|
669
|
+
it 'raises an OperationFailure' do
|
670
|
+
expect {
|
671
|
+
result
|
672
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
673
|
+
end
|
674
|
+
end
|
472
675
|
end
|
473
676
|
|
474
677
|
describe '#inspect' do
|
@@ -636,6 +839,19 @@ describe Mongo::Collection do
|
|
636
839
|
expect(response.deleted_count).to eq(1)
|
637
840
|
end
|
638
841
|
end
|
842
|
+
|
843
|
+
context 'when the delete fails', if: standalone? do
|
844
|
+
|
845
|
+
let(:result) do
|
846
|
+
collection_invalid_write_concern.delete_one
|
847
|
+
end
|
848
|
+
|
849
|
+
it 'raises an OperationFailure' do
|
850
|
+
expect {
|
851
|
+
result
|
852
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
853
|
+
end
|
854
|
+
end
|
639
855
|
end
|
640
856
|
|
641
857
|
describe '#delete_many' do
|
@@ -665,6 +881,54 @@ describe Mongo::Collection do
|
|
665
881
|
expect(authorized_collection.delete_many.deleted_count).to eq(2)
|
666
882
|
end
|
667
883
|
end
|
884
|
+
|
885
|
+
context 'when the deletes fail', if: standalone? do
|
886
|
+
|
887
|
+
let(:result) do
|
888
|
+
collection_invalid_write_concern.delete_many
|
889
|
+
end
|
890
|
+
|
891
|
+
it 'raises an OperationFailure' do
|
892
|
+
expect {
|
893
|
+
result
|
894
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
895
|
+
end
|
896
|
+
end
|
897
|
+
end
|
898
|
+
|
899
|
+
describe '#parallel_scan', unless: sharded? do
|
900
|
+
|
901
|
+
let(:documents) do
|
902
|
+
(1..200).map do |i|
|
903
|
+
{ name: "testing-scan-#{i}" }
|
904
|
+
end
|
905
|
+
end
|
906
|
+
|
907
|
+
before do
|
908
|
+
authorized_collection.insert_many(documents)
|
909
|
+
end
|
910
|
+
|
911
|
+
let(:cursors) do
|
912
|
+
authorized_collection.parallel_scan(2)
|
913
|
+
end
|
914
|
+
|
915
|
+
it 'returns an array of cursors', if: write_command_enabled? do
|
916
|
+
cursors.each do |cursor|
|
917
|
+
expect(cursor.class).to be(Mongo::Cursor)
|
918
|
+
end
|
919
|
+
end
|
920
|
+
|
921
|
+
it 'returns the correct number of documents', if: write_command_enabled? do
|
922
|
+
expect(
|
923
|
+
cursors.reduce(0) { |total, cursor| total + cursor.to_a.size }
|
924
|
+
).to eq(200)
|
925
|
+
end
|
926
|
+
|
927
|
+
it 'raises an error', unless: write_command_enabled? do
|
928
|
+
expect {
|
929
|
+
cursors
|
930
|
+
}.to raise_error(Mongo::Error::OperationFailure)
|
931
|
+
end
|
668
932
|
end
|
669
933
|
|
670
934
|
describe '#replace_one' do
|
@@ -760,6 +1024,19 @@ describe Mongo::Collection do
|
|
760
1024
|
expect(updated).to be_empty
|
761
1025
|
end
|
762
1026
|
end
|
1027
|
+
|
1028
|
+
context 'when the replace fails' do
|
1029
|
+
|
1030
|
+
let(:result) do
|
1031
|
+
authorized_collection.replace_one(selector, { '$s' => 'test1' })
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
it 'raises an OperationFailure' do
|
1035
|
+
expect {
|
1036
|
+
result
|
1037
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
1038
|
+
end
|
1039
|
+
end
|
763
1040
|
end
|
764
1041
|
|
765
1042
|
describe '#update_many' do
|
@@ -853,6 +1130,19 @@ describe Mongo::Collection do
|
|
853
1130
|
expect(updated).to be_empty
|
854
1131
|
end
|
855
1132
|
end
|
1133
|
+
|
1134
|
+
context 'when the updates fail' do
|
1135
|
+
|
1136
|
+
let(:result) do
|
1137
|
+
authorized_collection.update_many(selector, { '$s'=> { field: 'testing' } })
|
1138
|
+
end
|
1139
|
+
|
1140
|
+
it 'raises an OperationFailure' do
|
1141
|
+
expect {
|
1142
|
+
result
|
1143
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
1144
|
+
end
|
1145
|
+
end
|
856
1146
|
end
|
857
1147
|
|
858
1148
|
describe '#update_one' do
|
@@ -942,6 +1232,19 @@ describe Mongo::Collection do
|
|
942
1232
|
expect(updated).to be_empty
|
943
1233
|
end
|
944
1234
|
end
|
1235
|
+
|
1236
|
+
context 'when the update fails' do
|
1237
|
+
|
1238
|
+
let(:result) do
|
1239
|
+
authorized_collection.update_one(selector, { '$s'=> { field: 'testing' } })
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
it 'raises an OperationFailure' do
|
1243
|
+
expect {
|
1244
|
+
result
|
1245
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
1246
|
+
end
|
1247
|
+
end
|
945
1248
|
end
|
946
1249
|
|
947
1250
|
describe '#find_one_and_delete' do
|
@@ -950,11 +1253,11 @@ describe Mongo::Collection do
|
|
950
1253
|
authorized_collection.insert_many([{ field: 'test1' }])
|
951
1254
|
end
|
952
1255
|
|
953
|
-
|
1256
|
+
let(:selector) do
|
1257
|
+
{ field: 'test1' }
|
1258
|
+
end
|
954
1259
|
|
955
|
-
|
956
|
-
{ field: 'test1' }
|
957
|
-
end
|
1260
|
+
context 'when a matching document is found' do
|
958
1261
|
|
959
1262
|
context 'when no options are provided' do
|
960
1263
|
|
@@ -1026,18 +1329,31 @@ describe Mongo::Collection do
|
|
1026
1329
|
expect(document).to be_nil
|
1027
1330
|
end
|
1028
1331
|
end
|
1029
|
-
end
|
1030
1332
|
|
1031
|
-
|
1333
|
+
context 'when the operation fails', if: write_command_enabled? do
|
1032
1334
|
|
1033
|
-
|
1034
|
-
|
1335
|
+
let(:result) do
|
1336
|
+
authorized_collection.find_one_and_delete(selector, max_time_ms: 0.1)
|
1337
|
+
end
|
1338
|
+
|
1339
|
+
it 'raises an OperationFailure' do
|
1340
|
+
expect {
|
1341
|
+
result
|
1342
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
1343
|
+
end
|
1035
1344
|
end
|
1345
|
+
end
|
1346
|
+
|
1347
|
+
describe '#find_one_and_update' do
|
1036
1348
|
|
1037
1349
|
let(:selector) do
|
1038
1350
|
{ field: 'test1' }
|
1039
1351
|
end
|
1040
1352
|
|
1353
|
+
before do
|
1354
|
+
authorized_collection.insert_many([{ field: 'test1' }])
|
1355
|
+
end
|
1356
|
+
|
1041
1357
|
context 'when a matching document is found' do
|
1042
1358
|
|
1043
1359
|
context 'when no options are provided' do
|
@@ -1167,6 +1483,19 @@ describe Mongo::Collection do
|
|
1167
1483
|
end
|
1168
1484
|
end
|
1169
1485
|
end
|
1486
|
+
|
1487
|
+
context 'when the operation fails', if: write_command_enabled? do
|
1488
|
+
|
1489
|
+
let(:result) do
|
1490
|
+
authorized_collection.find_one_and_update(selector, { '$set' => { field: 'testing' }}, max_time_ms: 0.1)
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
it 'raises an OperationFailure' do
|
1494
|
+
expect {
|
1495
|
+
result
|
1496
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
1497
|
+
end
|
1498
|
+
end
|
1170
1499
|
end
|
1171
1500
|
|
1172
1501
|
describe '#find_one_and_replace' do
|
@@ -1282,5 +1611,18 @@ describe Mongo::Collection do
|
|
1282
1611
|
}.to raise_error(Mongo::Error::OperationFailure)
|
1283
1612
|
end
|
1284
1613
|
end
|
1614
|
+
|
1615
|
+
context 'when the operation fails', if: write_command_enabled? do
|
1616
|
+
|
1617
|
+
let(:result) do
|
1618
|
+
authorized_collection.find_one_and_replace(selector, { field: 'testing' }, max_time_ms: 0.1)
|
1619
|
+
end
|
1620
|
+
|
1621
|
+
it 'raises an OperationFailure' do
|
1622
|
+
expect {
|
1623
|
+
result
|
1624
|
+
}.to raise_exception(Mongo::Error::OperationFailure)
|
1625
|
+
end
|
1626
|
+
end
|
1285
1627
|
end
|
1286
1628
|
end
|