@@ -157,6 +157,7 @@ defmodule Mongo.BulkWrite do
157
157
import Mongo.Utils
158
158
alias Mongo.UnorderedBulk
159
159
alias Mongo.OrderedBulk
160
+ alias Mongo.BulkWriteResult
160
161
161
162
@ doc """
162
163
Executes unordered and ordered bulk writes.
@@ -176,7 +177,7 @@ defmodule Mongo.BulkWrite do
176
177
If a group (inserts, updates or deletes) exceeds the limit `maxWriteBatchSize` it will be split into chunks.
177
178
Everything is done in memory, so this use case is limited by memory. A better approach seems to use streaming bulk writes.
178
179
"""
179
- @ spec write ( GenServer . server , ( UnorderedBulk . t | OrderedBulk . t ) , Keyword . t ) :: Keyword . t
180
+ @ spec write ( GenServer . server , ( UnorderedBulk . t | OrderedBulk . t ) , Keyword . t ) :: Mongo.BulkWriteResult . t
180
181
def write ( topology_pid , % UnorderedBulk { } = bulk , opts ) do
181
182
182
183
write_concern = write_concern ( opts )
@@ -190,16 +191,7 @@ defmodule Mongo.BulkWrite do
190
191
191
192
write_concern = write_concern ( opts )
192
193
193
- empty = % {
194
- acknowledged: acknowledged ( write_concern ) ,
195
- insertedCount: 0 ,
196
- matchedCount: 0 ,
197
- deletedCount: 0 ,
198
- upsertedCount: 0 ,
199
- modifiedCount: 0 ,
200
- upsertedIds: [ ] ,
201
- insertedIds: [ ] ,
202
- }
194
+ empty = % BulkWriteResult { acknowledged: acknowledged ( write_concern ) }
203
195
204
196
with { :ok , conn , _ , _ } <- Mongo . select_server ( topology_pid , :write , opts ) ,
205
197
{ :ok , limits } <- Mongo . limits ( conn ) ,
@@ -217,21 +209,21 @@ defmodule Mongo.BulkWrite do
217
209
end
218
210
end
219
211
220
- defp merge ( :insert , count , ids , % { :insertedCount => value , :insertedIds => current_ids } = result ) do
221
- % { result | insertedCount : value + count , insertedIds : current_ids ++ ids }
212
+ defp merge ( :insert , count , ids , % BulkWriteResult { :inserted_count => value , :inserted_ids => current_ids } = result ) do
213
+ % BulkWriteResult { result | inserted_count : value + count , inserted_ids : current_ids ++ ids }
222
214
end
223
215
defp merge ( :update , matched , modified , upserts , ids ,
224
- % { :matchedCount => matched_count ,
225
- :modifiedCount => modified_count ,
226
- :upsertedCount => upserted_count ,
227
- :upsertedIds => current_ids } = result ) do
228
- % { result | matchedCount : matched_count + matched ,
229
- modifiedCount : modified_count + modified ,
230
- upsertedCount : upserted_count + upserts ,
231
- upsertedIds : current_ids ++ ids }
216
+ % BulkWriteResult { :matched_count => matched_count ,
217
+ :modified_count => modified_count ,
218
+ :upserted_count => upserted_count ,
219
+ :upserted_ids => current_ids } = result ) do
220
+ % BulkWriteResult { result | matched_count : matched_count + matched ,
221
+ modified_count : modified_count + modified ,
222
+ upserted_count : upserted_count + upserts ,
223
+ upserted_ids : current_ids ++ ids }
232
224
end
233
- defp merge ( :delete , count , % { :deletedCount => value } = result ) do
234
- % { result | deletedCount : value + count }
225
+ defp merge ( :delete , count , % BulkWriteResult { :deleted_count => value } = result ) do
226
+ % BulkWriteResult { result | deleted_count : value + count }
235
227
end
236
228
defp merge ( _other , _count , result ) , do: result
237
229
@@ -264,15 +256,15 @@ defmodule Mongo.BulkWrite do
264
256
{ _ , { matched , modified , upserts , upsert_ids } } <- one_bulk_write_operation ( conn , :update , coll , updates , write_concern , max_batch_size , opts ) ,
265
257
{ _ , deletes } <- one_bulk_write_operation ( conn , :delete , coll , deletes , write_concern , max_batch_size , opts ) do
266
258
267
- % {
259
+ % BulkWriteResult {
268
260
acknowledged: acknowledged ( write_concern ) ,
269
- insertedCount : inserts ,
270
- insertedIds : ids ,
271
- matchedCount : matched ,
272
- deletedCount : deletes ,
273
- modifiedCount : modified ,
274
- upsertedCount : upserts ,
275
- upsertedIds : upsert_ids
261
+ inserted_count : inserts ,
262
+ inserted_ids : ids ,
263
+ matched_count : matched ,
264
+ deleted_count : deletes ,
265
+ modified_count : modified ,
266
+ upserted_count : upserts ,
267
+ upserted_ids : upsert_ids
276
268
}
277
269
end
278
270
end
0 commit comments