June 2017
Intermediate to advanced
536 pages
9h 49m
English
Deletion is done in a manner similar to write and update, in that it uses an instance of the MongoDBDriverBulkWrite object. This time, we are using the instance delete() method, which accepts filter and delete options:
<?phprequire_once __DIR__ . '/vendor/autoload.php';try { $manager = new MongoDBDriverManager('mongodb://localhost:27017'); $bulkWrite = new MongoDBDriverBulkWrite; $bulkWrite->delete( // filter [ 'name' => [ '$regex' => '^iPhone' ] ], // Delete options ['limit' => false] ); $writeConcern = new MongoDBDriverWriteConcern(MongoDBDriverWriteConcern::MAJORITY, 1000); $result = $manager->executeBulkWrite('foggyline.products', $bulkWrite, $writeConcern); if ($result->getDeletedCount()) { echo 'Record(s) deleted.', PHP_EOL ...
Read now
Unlock full access