conditional to execute query mongo

0

I have the following code, and I want to know if there is any mongodb function that returns true or false depending on whether the query was executed correctly or not.

public function removepopup($id){
    $collection = $this->connect()->deleteOne(['_id' => new MongoDB\BSON\ObjectID( $id )]);
}
    
asked by francesc 24.05.2018 в 10:15
source

1 answer

0

The deleteOne () method, from what I have read in the documentation, returns an Object of type MongoDB \ DeleteResult, link \ DeleteResult. It is used to encapsulate PHP object link . Well, the php object has some methods, I'll write a code to see if it works for you, based on the method: link

public function removepopup($id){
    $collection = $this->connect()->deleteOne(['_id' => new MongoDB\BSON\ObjectID( $id )]);
     if($collection->getDeletedCount() == 0){
          //No se ha eliminado ninguna fila
          return false;
     }
     return true;
}
    
answered by 24.05.2018 в 12:12