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
@@ -21,8 +21,7 @@ module Mongo
|
|
21
21
|
#
|
22
22
|
# @since 2.0.0
|
23
23
|
class Result < Operation::Result
|
24
|
-
|
25
|
-
attr_reader :indexes
|
24
|
+
include BulkMergable
|
26
25
|
|
27
26
|
# The number of modified docs field in the result.
|
28
27
|
#
|
@@ -87,65 +86,6 @@ module Mongo
|
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
|
-
# Set a list of indexes of the operations creating this result.
|
91
|
-
#
|
92
|
-
# @example Set the list of indexes.
|
93
|
-
# result.set_indexes([1,2,3])
|
94
|
-
#
|
95
|
-
# @return [ self ] The result.
|
96
|
-
#
|
97
|
-
# @since 2.0.0
|
98
|
-
def set_indexes(indexes)
|
99
|
-
@indexes = indexes
|
100
|
-
self
|
101
|
-
end
|
102
|
-
|
103
|
-
# Aggregate the write errors returned from this result.
|
104
|
-
#
|
105
|
-
# @example Aggregate the write errors.
|
106
|
-
# result.aggregate_write_errors
|
107
|
-
#
|
108
|
-
# @return [ Array ] The aggregate write errors.
|
109
|
-
#
|
110
|
-
# @since 2.0.0
|
111
|
-
def aggregate_write_errors
|
112
|
-
@replies.reduce(nil) do |errors, reply|
|
113
|
-
if write_errors = reply.documents.first['writeErrors']
|
114
|
-
errors ||= []
|
115
|
-
write_errors.each do |write_error|
|
116
|
-
errors << write_error.merge('index' => indexes[write_error['index']])
|
117
|
-
end
|
118
|
-
end
|
119
|
-
errors
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
# Aggregate the write concern errors returned from this result.
|
124
|
-
#
|
125
|
-
# @example Aggregate the write concern errors.
|
126
|
-
# result.aggregate_write_concern_errors
|
127
|
-
#
|
128
|
-
# @return [ Array ] The aggregate write concern errors.
|
129
|
-
#
|
130
|
-
# @since 2.0.0
|
131
|
-
def aggregate_write_concern_errors
|
132
|
-
@replies.each_with_index.reduce(nil) do |errors, (reply, i)|
|
133
|
-
if write_concern_errors = reply.documents.first['writeConcernError']
|
134
|
-
errors ||= []
|
135
|
-
write_concern_errors.each do |write_concern_error|
|
136
|
-
errors << write_concern_error.merge('index' =>
|
137
|
-
indexes[write_concern_error['index']])
|
138
|
-
end
|
139
|
-
elsif reply.documents.first['errmsg']
|
140
|
-
errors ||= []
|
141
|
-
errors << { 'errmsg' => reply.documents.first['errmsg'],
|
142
|
-
'index' => indexes[i],
|
143
|
-
'code' => reply.documents.first['code'] }
|
144
|
-
end
|
145
|
-
errors
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
89
|
private
|
150
90
|
|
151
91
|
def upsert?(reply)
|
@@ -158,8 +98,7 @@ module Mongo
|
|
158
98
|
#
|
159
99
|
# @since 2.0.0
|
160
100
|
class LegacyResult < Operation::Result
|
161
|
-
|
162
|
-
attr_reader :indexes
|
101
|
+
include LegacyBulkMergable
|
163
102
|
|
164
103
|
# The updated existing field in the result.
|
165
104
|
#
|
@@ -204,87 +143,8 @@ module Mongo
|
|
204
143
|
end
|
205
144
|
end
|
206
145
|
|
207
|
-
# Gets the number of documents modified.
|
208
|
-
#
|
209
|
-
# @example Get the modified count.
|
210
|
-
# result.n_modified
|
211
|
-
#
|
212
|
-
# @return [ nil ] nil for legacy.
|
213
|
-
#
|
214
|
-
# @since 2.0.0
|
215
|
-
def n_modified
|
216
|
-
nil
|
217
|
-
end
|
218
|
-
|
219
|
-
# Set a list of indexes of the operations creating this result.
|
220
|
-
#
|
221
|
-
# @example Set the list of indexes.
|
222
|
-
# result.set_indexes([1,2,3])
|
223
|
-
#
|
224
|
-
# @return [ self ] The result.
|
225
|
-
#
|
226
|
-
# @since 2.0.0
|
227
|
-
def set_indexes(indexes)
|
228
|
-
@indexes = indexes
|
229
|
-
self
|
230
|
-
end
|
231
|
-
|
232
|
-
# Aggregate the write errors returned from this result.
|
233
|
-
#
|
234
|
-
# @example Aggregate the write errors.
|
235
|
-
# result.aggregate_write_errors
|
236
|
-
#
|
237
|
-
# @return [ Array ] The aggregate write errors.
|
238
|
-
#
|
239
|
-
# @since 2.0.0
|
240
|
-
def aggregate_write_errors
|
241
|
-
@replies.each_with_index.reduce(nil) do |errors, (reply, i)|
|
242
|
-
if reply_write_errors?(reply)
|
243
|
-
errors ||= []
|
244
|
-
errors << { 'errmsg' => reply.documents.first[Error::ERROR],
|
245
|
-
'index' => indexes[i],
|
246
|
-
'code' => reply.documents.first[Error::CODE] }
|
247
|
-
end
|
248
|
-
errors
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
# Aggregate the write concern errors returned from this result.
|
253
|
-
#
|
254
|
-
# @example Aggregate the write concern errors.
|
255
|
-
# result.aggregate_write_concern_errors
|
256
|
-
#
|
257
|
-
# @return [ Array ] The aggregate write concern errors.
|
258
|
-
#
|
259
|
-
# @since 2.0.0
|
260
|
-
def aggregate_write_concern_errors
|
261
|
-
@replies.each_with_index.reduce(nil) do |errors, (reply, i)|
|
262
|
-
# @todo: only raise if error is timeout
|
263
|
-
if error = reply_write_errors?(reply)
|
264
|
-
errors ||= []
|
265
|
-
note = reply.documents.first['wnote'] || reply.documents.first['jnote']
|
266
|
-
if note
|
267
|
-
code = reply.documents.first['code'] || "bad value constant"
|
268
|
-
error_string = "#{code}: #{note}"
|
269
|
-
else
|
270
|
-
code = reply.documents.first['code'] || "unknown error constant"
|
271
|
-
error_string = "#{code}: #{error}"
|
272
|
-
end
|
273
|
-
errors << { 'errmsg' => error_string,
|
274
|
-
'index' => indexes[i],
|
275
|
-
'code' => code }
|
276
|
-
end
|
277
|
-
errors
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
146
|
private
|
282
147
|
|
283
|
-
def reply_write_errors?(reply)
|
284
|
-
reply.documents.first[Error::ERROR] ||
|
285
|
-
reply.documents.first[Error::ERRMSG]
|
286
|
-
end
|
287
|
-
|
288
148
|
def upsert?(reply)
|
289
149
|
!reply.documents.first[UPDATED_EXISTING]
|
290
150
|
end
|
@@ -41,7 +41,7 @@ module Mongo
|
|
41
41
|
# @example Execute the operation.
|
42
42
|
# operation.execute(context)
|
43
43
|
#
|
44
|
-
# @
|
44
|
+
# @param [ Server::Context ] context The context for this operation.
|
45
45
|
#
|
46
46
|
# @return [ Result ] The operation result.
|
47
47
|
#
|
@@ -25,7 +25,7 @@ module Mongo
|
|
25
25
|
# The context gets a connection on which the operation
|
26
26
|
# is sent in the block.
|
27
27
|
#
|
28
|
-
# @
|
28
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
29
29
|
#
|
30
30
|
# @return [ Result ] The operation response, if there is one.
|
31
31
|
#
|
@@ -39,7 +39,7 @@ module Mongo
|
|
39
39
|
# Merge this operation with another operation, returning a new one.
|
40
40
|
# Requires that the collection and database of the two ops are the same.
|
41
41
|
#
|
42
|
-
# @
|
42
|
+
# @param[ Object ] The other operation.
|
43
43
|
#
|
44
44
|
# @return [ Object ] A new operation merging this one and another.
|
45
45
|
#
|
@@ -67,7 +67,7 @@ module Mongo
|
|
67
67
|
# If an operation including this module doesn't define #merge!, neither
|
68
68
|
# #merge nor #merge! will be allowed.
|
69
69
|
#
|
70
|
-
# @
|
70
|
+
# @param[ Object ] The other operation.
|
71
71
|
#
|
72
72
|
# @raise [ Exception ] Merging is not supported for this operation.
|
73
73
|
#
|
@@ -57,7 +57,7 @@ module Mongo
|
|
57
57
|
# @example Execute the operation.
|
58
58
|
# operation.execute(context)
|
59
59
|
#
|
60
|
-
# @
|
60
|
+
# @param [ Server::Context ] context The context for this operation.
|
61
61
|
#
|
62
62
|
# @return [ Result ] The operation response, if there is one.
|
63
63
|
#
|
@@ -37,7 +37,7 @@ module Mongo
|
|
37
37
|
# The context gets a connection on which the operation
|
38
38
|
# is sent in the block.
|
39
39
|
#
|
40
|
-
# @
|
40
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
41
41
|
#
|
42
42
|
# @return [ Result ] The operation response, if there is one.
|
43
43
|
#
|
@@ -45,7 +45,7 @@ module Mongo
|
|
45
45
|
# @example Execute the operation.
|
46
46
|
# operation.execute(context)
|
47
47
|
#
|
48
|
-
# @
|
48
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
49
49
|
#
|
50
50
|
# @return [ Result ] The operation response, if there is one.
|
51
51
|
#
|
@@ -38,7 +38,7 @@ module Mongo
|
|
38
38
|
# The context gets a connection on which the operation
|
39
39
|
# is sent in the block.
|
40
40
|
#
|
41
|
-
# @
|
41
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
42
42
|
#
|
43
43
|
# @return [ Result ] The indexes operation response.
|
44
44
|
#
|
@@ -43,7 +43,7 @@ module Mongo
|
|
43
43
|
# @example Execute the operation.
|
44
44
|
# operation.execute(context)
|
45
45
|
#
|
46
|
-
# @
|
46
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
47
47
|
#
|
48
48
|
# @return [ Result ] The operation result.
|
49
49
|
#
|
@@ -45,7 +45,7 @@ module Mongo
|
|
45
45
|
# @example Execute the operation.
|
46
46
|
# operation.execute(context)
|
47
47
|
#
|
48
|
-
# @
|
48
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
49
49
|
#
|
50
50
|
# @return [ Result ] The operation result.
|
51
51
|
#
|
@@ -45,7 +45,7 @@ module Mongo
|
|
45
45
|
# The context gets a connection on which the operation
|
46
46
|
# is sent in the block.
|
47
47
|
#
|
48
|
-
# @
|
48
|
+
# @param [ Server::Context ] context The context for this operation.
|
49
49
|
#
|
50
50
|
# @return [ Result ] The operation response, if there is one.
|
51
51
|
#
|
@@ -61,11 +61,16 @@ module Mongo
|
|
61
61
|
# @since 2.0.0
|
62
62
|
CURSOR_IDS = :cursor_ids.freeze
|
63
63
|
|
64
|
-
# The field for
|
64
|
+
# The field for an index.
|
65
65
|
#
|
66
66
|
# @since 2.0.0
|
67
67
|
INDEX = :index.freeze
|
68
68
|
|
69
|
+
# The field for multiple indexes.
|
70
|
+
#
|
71
|
+
# @since 2.0.0
|
72
|
+
INDEXES = :indexes.freeze
|
73
|
+
|
69
74
|
# The field for index names.
|
70
75
|
#
|
71
76
|
# @since 2.0.0
|
@@ -255,6 +260,18 @@ module Mongo
|
|
255
260
|
spec[INDEX_NAME]
|
256
261
|
end
|
257
262
|
|
263
|
+
# Get the indexes from the specification.
|
264
|
+
#
|
265
|
+
# @example Get the index specifications.
|
266
|
+
# specifiable.indexes
|
267
|
+
#
|
268
|
+
# @return [ Hash ] The index specifications.
|
269
|
+
#
|
270
|
+
# @since 2.0.0
|
271
|
+
def indexes
|
272
|
+
spec[INDEXES]
|
273
|
+
end
|
274
|
+
|
258
275
|
# Create the new specifiable operation.
|
259
276
|
#
|
260
277
|
# @example Create the new specifiable operation.
|
@@ -12,6 +12,8 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require 'mongo/operation/write/bulk_mergable'
|
16
|
+
require 'mongo/operation/write/legacy_bulk_mergable'
|
15
17
|
require 'mongo/operation/write/delete'
|
16
18
|
require 'mongo/operation/write/bulk_delete'
|
17
19
|
require 'mongo/operation/write/insert'
|
@@ -49,14 +49,13 @@ module Mongo
|
|
49
49
|
class BulkDelete
|
50
50
|
include Executable
|
51
51
|
include Specifiable
|
52
|
-
include Batchable
|
53
52
|
|
54
53
|
# Execute the delete operation.
|
55
54
|
#
|
56
55
|
# @example Execute the operation.
|
57
56
|
# operation.execute(context)
|
58
57
|
#
|
59
|
-
# @
|
58
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
60
59
|
#
|
61
60
|
# @return [ Result ] The result.
|
62
61
|
#
|
@@ -74,7 +73,7 @@ module Mongo
|
|
74
73
|
# @example Set a write concern.
|
75
74
|
# new_op = operation.write_concern(:w => 2)
|
76
75
|
#
|
77
|
-
# @
|
76
|
+
# @param [ Hash ] wc The write concern.
|
78
77
|
#
|
79
78
|
# @since 2.0.0
|
80
79
|
def write_concern(wc = nil)
|
@@ -85,19 +84,10 @@ module Mongo
|
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
88
|
-
# The index of each delete as it was added onto the bulk object.
|
89
|
-
#
|
90
|
-
# @params [ Integer ] The index of each delete.
|
91
|
-
#
|
92
|
-
# @since 2.0.0
|
93
|
-
def indexes
|
94
|
-
@spec[:indexes] || []
|
95
|
-
end
|
96
|
-
|
97
87
|
private
|
98
88
|
|
99
89
|
def execute_write_command(context)
|
100
|
-
Result.new(Command::Delete.new(spec).execute(context))
|
90
|
+
Result.new(Command::Delete.new(spec).execute(context))
|
101
91
|
end
|
102
92
|
|
103
93
|
def execute_message(context)
|
@@ -105,13 +95,13 @@ module Mongo
|
|
105
95
|
context.with_connection do |connection|
|
106
96
|
result = LegacyResult.new(connection.dispatch([ m, gle ].compact))
|
107
97
|
if stop_sending?(result)
|
108
|
-
return result
|
98
|
+
return result
|
109
99
|
else
|
110
100
|
result.reply
|
111
101
|
end
|
112
102
|
end
|
113
103
|
end
|
114
|
-
LegacyResult.new(replies.compact.empty? ? nil : replies)
|
104
|
+
LegacyResult.new(replies.compact.empty? ? nil : replies)
|
115
105
|
end
|
116
106
|
|
117
107
|
def stop_sending?(result)
|
@@ -137,10 +127,6 @@ module Mongo
|
|
137
127
|
end
|
138
128
|
end
|
139
129
|
|
140
|
-
def batch_key
|
141
|
-
DELETES
|
142
|
-
end
|
143
|
-
|
144
130
|
def initialize_copy(original)
|
145
131
|
@spec = original.spec.dup
|
146
132
|
@spec[DELETES] = original.spec[DELETES].clone
|
@@ -46,16 +46,14 @@ module Mongo
|
|
46
46
|
#
|
47
47
|
# @since 2.0.0
|
48
48
|
class BulkInsert
|
49
|
-
include Executable
|
50
49
|
include Specifiable
|
51
|
-
include Batchable
|
52
50
|
|
53
51
|
# Execute the bulk insert operation.
|
54
52
|
#
|
55
53
|
# @example Execute the operation.
|
56
54
|
# operation.execute(context)
|
57
55
|
#
|
58
|
-
# @
|
56
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
59
57
|
#
|
60
58
|
# @return [ Result ] The operation result.
|
61
59
|
#
|
@@ -68,35 +66,10 @@ module Mongo
|
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
|
-
# Set the write concern on this operation.
|
72
|
-
#
|
73
|
-
# @example Set a write concern.
|
74
|
-
# new_op = operation.write_concern(:w => 2)
|
75
|
-
#
|
76
|
-
# @params [ Hash ] The write concern.
|
77
|
-
#
|
78
|
-
# @since 2.0.0
|
79
|
-
def write_concern(wc = nil)
|
80
|
-
if wc
|
81
|
-
self.class.new(spec.merge(write_concern: WriteConcern.get(wc)))
|
82
|
-
else
|
83
|
-
spec[WRITE_CONCERN]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# The index of each document as it was added onto the bulk object.
|
88
|
-
#
|
89
|
-
# @params [ Integer ] The index of each document.
|
90
|
-
#
|
91
|
-
# @since 2.0.0
|
92
|
-
def indexes
|
93
|
-
@spec[:indexes] || []
|
94
|
-
end
|
95
|
-
|
96
69
|
private
|
97
70
|
|
98
71
|
def execute_write_command(context)
|
99
|
-
Result.new(Command::Insert.new(spec).execute(context))
|
72
|
+
Result.new(Command::Insert.new(spec).execute(context))
|
100
73
|
end
|
101
74
|
|
102
75
|
def execute_message(context)
|
@@ -106,11 +79,11 @@ module Mongo
|
|
106
79
|
result = LegacyResult.new(connection.dispatch([ m, gle ].compact))
|
107
80
|
replies << result.reply
|
108
81
|
if stop_sending?(result)
|
109
|
-
return LegacyResult.new(replies)
|
82
|
+
return LegacyResult.new(replies)
|
110
83
|
end
|
111
84
|
end
|
112
85
|
end
|
113
|
-
LegacyResult.new(replies.compact.empty? ? nil : replies)
|
86
|
+
LegacyResult.new(replies.compact.empty? ? nil : replies)
|
114
87
|
end
|
115
88
|
|
116
89
|
def stop_sending?(result)
|
@@ -122,6 +95,11 @@ module Mongo
|
|
122
95
|
@spec.fetch(:ordered, true)
|
123
96
|
end
|
124
97
|
|
98
|
+
def initialize_copy(original)
|
99
|
+
@spec = original.spec.dup
|
100
|
+
@spec[DOCUMENTS] = original.spec[DOCUMENTS].clone
|
101
|
+
end
|
102
|
+
|
125
103
|
def gle
|
126
104
|
gle_message = ( ordered? && write_concern.get_last_error.nil? ) ?
|
127
105
|
Mongo::WriteConcern.get(:w => 1).get_last_error :
|
@@ -136,15 +114,6 @@ module Mongo
|
|
136
114
|
end
|
137
115
|
end
|
138
116
|
|
139
|
-
def batch_key
|
140
|
-
DOCUMENTS
|
141
|
-
end
|
142
|
-
|
143
|
-
def initialize_copy(original)
|
144
|
-
@spec = original.spec.dup
|
145
|
-
@spec[DOCUMENTS] = original.spec[DOCUMENTS].dup
|
146
|
-
end
|
147
|
-
|
148
117
|
def messages
|
149
118
|
if ordered? || gle
|
150
119
|
documents.collect do |doc|
|