|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\BulkWrite: #003 executed multiple times |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE); ?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 8 | + |
| 9 | +$manager = new MongoDB\Driver\Manager(STANDALONE); |
| 10 | + |
| 11 | +$insertBulk = new MongoDB\Driver\BulkWrite; |
| 12 | +$insertBulk->insert(['x' => 1]); |
| 13 | +$result = $manager->executeBulkWrite(NS, $insertBulk); |
| 14 | +printf("Inserted %d document(s)\n", $result->getInsertedCount()); |
| 15 | + |
| 16 | +$insertBulk = new MongoDB\Driver\BulkWrite; |
| 17 | +$insertBulk->insert(['x' => 1]); |
| 18 | +$result = $manager->executeBulkWrite(NS, $insertBulk); |
| 19 | +printf("Inserted %d document(s)\n", $result->getInsertedCount()); |
| 20 | + |
| 21 | +try { |
| 22 | + $result = $manager->executeBulkWrite(NS, $insertBulk); |
| 23 | + printf("Inserted %d document(s)\n", $result->getInsertedCount()); |
| 24 | +} catch (MongoDB\Driver\Exception\BulkWriteException $e) { |
| 25 | + printf("Write error: %s\n", $e->getWriteResult()->getWriteErrors()[0]->getMessage()); |
| 26 | +} |
| 27 | + |
| 28 | +$updateBulk = new MongoDB\Driver\BulkWrite; |
| 29 | +$updateBulk->update([], ['$inc' => ['x' => 1]]); |
| 30 | +$result = $manager->executeBulkWrite(NS, $updateBulk); |
| 31 | +printf("Updated %d document(s)\n", $result->getModifiedCount()); |
| 32 | + |
| 33 | +$result = $manager->executeBulkWrite(NS, $updateBulk); |
| 34 | +printf("Updated %d document(s)\n", $result->getModifiedCount()); |
| 35 | + |
| 36 | +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([])); |
| 37 | +var_dump($cursor->toArray()); |
| 38 | + |
| 39 | +$deleteBulk = new MongoDB\Driver\BulkWrite; |
| 40 | +$deleteBulk->delete([], ['limit' => 1]); |
| 41 | +$result = $manager->executeBulkWrite(NS, $deleteBulk); |
| 42 | +printf("Deleted %d document(s)\n", $result->getDeletedCount()); |
| 43 | + |
| 44 | +$result = $manager->executeBulkWrite(NS, $deleteBulk); |
| 45 | +printf("Deleted %d document(s)\n", $result->getDeletedCount()); |
| 46 | + |
| 47 | +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([])); |
| 48 | +var_dump($cursor->toArray()); |
| 49 | + |
| 50 | +?> |
| 51 | +===DONE=== |
| 52 | +<?php exit(0); ?> |
| 53 | +--EXPECTF-- |
| 54 | +Inserted 1 document(s) |
| 55 | +Inserted 1 document(s) |
| 56 | +Write error: E11000 duplicate key error%s |
| 57 | +Updated 1 document(s) |
| 58 | +Updated 1 document(s) |
| 59 | +array(2) { |
| 60 | + [0]=> |
| 61 | + object(stdClass)#%d (%d) { |
| 62 | + ["_id"]=> |
| 63 | + object(MongoDB\BSON\ObjectID)#%d (%d) { |
| 64 | + ["oid"]=> |
| 65 | + string(24) "%x" |
| 66 | + } |
| 67 | + ["x"]=> |
| 68 | + int(3) |
| 69 | + } |
| 70 | + [1]=> |
| 71 | + object(stdClass)#%d (%d) { |
| 72 | + ["_id"]=> |
| 73 | + object(MongoDB\BSON\ObjectID)#%d (%d) { |
| 74 | + ["oid"]=> |
| 75 | + string(24) "%x" |
| 76 | + } |
| 77 | + ["x"]=> |
| 78 | + int(1) |
| 79 | + } |
| 80 | +} |
| 81 | +Deleted 1 document(s) |
| 82 | +Deleted 1 document(s) |
| 83 | +array(0) { |
| 84 | +} |
| 85 | +===DONE=== |
0 commit comments