7
7
use MongoDB \Driver \Query ;
8
8
use MongoDB \Driver \ReadPreference ;
9
9
use MongoDB \Driver \Result ;
10
- use MongoDB \Driver \WriteBatch ;
10
+ use MongoDB \Driver \BulkWrite ;
11
11
use MongoDB \Driver \WriteConcern ;
12
12
13
13
class Collection
@@ -287,7 +287,7 @@ public function getBulkOptions()
287
287
}
288
288
289
289
/**
290
- * Adds a full set of write operations into a batch and executes it
290
+ * Adds a full set of write operations into a bulk and executes it
291
291
*
292
292
* The syntax of the $bulk array is:
293
293
* $bulk = [
@@ -337,7 +337,7 @@ public function bulkWrite(array $bulk, array $options = array())
337
337
{
338
338
$ options = array_merge ($ this ->getBulkOptions (), $ options );
339
339
340
- $ batch = new WriteBatch ($ options ["ordered " ]);
340
+ $ bulk = new BulkWrite ($ options ["ordered " ]);
341
341
342
342
foreach ($ bulk as $ n => $ op ) {
343
343
foreach ($ op as $ opname => $ args ) {
@@ -347,7 +347,7 @@ public function bulkWrite(array $bulk, array $options = array())
347
347
348
348
switch ($ opname ) {
349
349
case "insertOne " :
350
- $ batch ->insert ($ args [0 ]);
350
+ $ bulk ->insert ($ args [0 ]);
351
351
break ;
352
352
353
353
case "updateMany " :
@@ -356,7 +356,7 @@ public function bulkWrite(array $bulk, array $options = array())
356
356
}
357
357
$ options = array_merge ($ this ->getWriteOptions (), isset ($ args [2 ]) ? $ args [2 ] : array (), array ("limit " => 0 ));
358
358
359
- $ batch ->update ($ args [0 ], $ args [1 ], $ options );
359
+ $ bulk ->update ($ args [0 ], $ args [1 ], $ options );
360
360
break ;
361
361
362
362
case "updateOne " :
@@ -368,7 +368,7 @@ public function bulkWrite(array $bulk, array $options = array())
368
368
throw new \InvalidArgumentException ("First key in \$update must be a \$operator " );
369
369
}
370
370
371
- $ batch ->update ($ args [0 ], $ args [1 ], $ options );
371
+ $ bulk ->update ($ args [0 ], $ args [1 ], $ options );
372
372
break ;
373
373
374
374
case "replaceOne " :
@@ -380,25 +380,25 @@ public function bulkWrite(array $bulk, array $options = array())
380
380
throw new \InvalidArgumentException ("First key in \$update must NOT be a \$operator " );
381
381
}
382
382
383
- $ batch ->update ($ args [0 ], $ args [1 ], $ options );
383
+ $ bulk ->update ($ args [0 ], $ args [1 ], $ options );
384
384
break ;
385
385
386
386
case "deleteOne " :
387
387
$ options = array_merge ($ this ->getWriteOptions (), isset ($ args [1 ]) ? $ args [1 ] : array (), array ("limit " => 1 ));
388
- $ batch ->delete ($ args [0 ], $ options );
388
+ $ bulk ->delete ($ args [0 ], $ options );
389
389
break ;
390
390
391
391
case "deleteMany " :
392
392
$ options = array_merge ($ this ->getWriteOptions (), isset ($ args [1 ]) ? $ args [1 ] : array (), array ("limit " => 0 ));
393
- $ batch ->delete ($ args [0 ], $ options );
393
+ $ bulk ->delete ($ args [0 ], $ options );
394
394
break ;
395
395
396
396
default :
397
397
throw new \InvalidArgumentException (sprintf ("Unknown operation type called '%s' (operation#%d) " , $ opname , $ n ));
398
398
}
399
399
}
400
400
}
401
- return $ this ->manager ->executeWriteBatch ($ this ->ns , $ batch , $ this ->wc );
401
+ return $ this ->manager ->executeBulkWrite ($ this ->ns , $ bulk , $ this ->wc );
402
402
}
403
403
404
404
/**
@@ -415,9 +415,9 @@ public function insertOne(array $document)
415
415
{
416
416
$ options = array_merge ($ this ->getWriteOptions ());
417
417
418
- $ batch = new WriteBatch ($ options ["ordered " ]);
419
- $ id = $ batch ->insert ($ document );
420
- $ wr = $ this ->manager ->executeWriteBatch ($ this ->ns , $ batch , $ this ->wc );
418
+ $ bulk = new BulkWrite ($ options ["ordered " ]);
419
+ $ id = $ bulk ->insert ($ document );
420
+ $ wr = $ this ->manager ->executeBulkWrite ($ this ->ns , $ bulk , $ this ->wc );
421
421
422
422
return new InsertResult ($ wr , $ id );
423
423
}
@@ -430,9 +430,9 @@ final protected function _delete($filter, $limit = 1)
430
430
{
431
431
$ options = array_merge ($ this ->getWriteOptions (), array ("limit " => $ limit ));
432
432
433
- $ batch = new WriteBatch ($ options ["ordered " ]);
434
- $ batch ->delete ($ filter , $ options );
435
- return $ this ->manager ->executeWriteBatch ($ this ->ns , $ batch , $ this ->wc );
433
+ $ bulk = new BulkWrite ($ options ["ordered " ]);
434
+ $ bulk ->delete ($ filter , $ options );
435
+ return $ this ->manager ->executeBulkWrite ($ this ->ns , $ bulk , $ this ->wc );
436
436
}
437
437
438
438
/**
@@ -475,9 +475,9 @@ protected function _update($filter, $update, $options)
475
475
{
476
476
$ options = array_merge ($ this ->getWriteOptions (), $ options );
477
477
478
- $ batch = new WriteBatch ($ options ["ordered " ]);
479
- $ batch ->update ($ filter , $ update , $ options );
480
- return $ this ->manager ->executeWriteBatch ($ this ->ns , $ batch , $ this ->wc );
478
+ $ bulk = new BulkWrite ($ options ["ordered " ]);
479
+ $ bulk ->update ($ filter , $ update , $ options );
480
+ return $ this ->manager ->executeBulkWrite ($ this ->ns , $ bulk , $ this ->wc );
481
481
}
482
482
483
483
/**
0 commit comments