PHP: Repair Mongodb using MongoDB\Driver-ThrowExceptions

Exception or error:

I need to rewrite this codes to using MongoDB\Driver.

But I cant find how to repair database.

Please anyone give me a example to repair MongoDB database with MongoDB\Driver.

Thank you.

codes using MongoClinent:

$mongo = new MongoClient('mongodb://localhost:27017');
$db = $mongo->selectDB('databaseName');
$collection = $db->selectCollection('collectionName');
$date = date("Y-m-d",strtotime("-1 month"));
$result = $collection->remove(array('date' => array( '$lt' => $date)));
if(0 < $result["n"]){

code using MongoDB\Driver:

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$date = date("Y-m-d",strtotime("-1 month"));
$bulk->delete(['date' => ['$lt' => $date], ['limit' => false]]);
$result = $manager->executeBulkWrite('databaseName.collectionName', $bulk);
if(0 < $result["n"]){
    // *** I don't know how to write ***
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *