Пример #1
0
 public function remove()
 {
     // Get options
     $options = func_num_args() > 0 ? (array) func_get_arg(0) : array();
     // Remove document
     try {
         $bulk = new \MongoDB\Driver\BulkWrite();
         $bulk->delete($this->_prepareQuery($this->query['search']), $options);
         $this->database->getDriver()->executeBulkWrite($this->name, $bulk);
     } catch (\Exception $e) {
         throw new Exception($e->getMessage());
     }
 }
Пример #2
0
 public function Delete($collection, SelectionCriteria $where)
 {
     //check for input and get an associative array
     if (!is_string($collection) || strlen($collection) < 3 || strpos($collection, '.') < 1) {
         throw new \InvalidArgumentException('The collection name to be filled on the database must be given as "database.collection"');
     }
     //create a bulkwriter and fill it
     $bulk = new \MongoDB\Driver\BulkWrite(['ordered' => true]);
     //execute the write operation
     try {
         $bulk->delete(self::resolveSelectionCriteria($where), ['limit' => false]);
         //$writeConcern = new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000);
         $result = $this->connection['db_manager']->executeBulkWrite($collection, $bulk);
     } catch (\MongoDB\Driver\Exception\BulkWriteException $ex) {
         throw new DatabaseException('Deletion failed due to a write error', 5);
     } catch (\MongoDB\Driver\Exception\InvalidArgumentException $ex) {
         throw new DatabaseException('Deletion failed due to an error occurred while parsing data', 5);
     } catch (\MongoDB\Driver\Exception\ConnectionException $ex) {
         throw new DatabaseException('Deletion failed due to an authentication error', 5);
     } catch (\MongoDB\Driver\Exception\AuthenticationException $ex) {
         throw new DatabaseException('Deletion failed due to an error on connection', 5);
     } catch (\MongoDB\Driver\Exception\RuntimeException $ex) {
         throw new DatabaseException('Deletion failed due to an unknown error', 5);
     }
     //return the number of remover documents
     return $result->getDeletedCount();
 }
Пример #3
0
 /**
  * 删
  * @param array $deleteOptions
  * @param string $wstring
  * @param int $wtimeout
  * @return mixed
  */
 public function delete($deleteOptions = ["limit" => 1], $wstring = \MongoDB\Driver\WriteConcern::MAJORITY, $wtimeout = 1000)
 {
     try {
         $wc = new \MongoDB\Driver\WriteConcern($wstring, $wtimeout);
         $bulk = new \MongoDB\Driver\BulkWrite();
         $filter = $this->wheres;
         if (count($filter) < 1 && $deleteOptions['limit'] == 1) {
             throw new \Exception('filter is error!');
         }
         $bulk->delete($filter, $deleteOptions);
         $dbc = $this->database . '.' . $this->collection;
         $result = $this->manager->executeBulkWrite($dbc, $bulk, $wc);
         $this->result = $result;
         //删除几条
         return $result->getDeletedCount();
     } catch (\Exception $e) {
         $this->showError($e);
     }
 }
Пример #4
0
 public function Delete($id_string)
 {
     global $db;
     $cn = self::CollectionName();
     $bw = new MongoDB\Driver\BulkWrite();
     $_id = new MongoDB\BSON\ObjectId($id_string);
     $bw->delete(['_id' => $_id], ['limit' => 1]);
     $result = $db->executeBulkWrite($cn, $bw);
     $response = [];
     $response['editor_action'] = 'reload';
     $response['db_output'] = $result;
     return $response;
 }
Пример #5
0
 public function delete($tname, $filter, $options = [])
 {
     $b = new MongoDB\Driver\BulkWrite();
     $b->delete($filter, $options);
     return $this->mongo->executeBulkWrite($this->getCName($tname), $b, $this->w);
 }
 /**
  * Deletes a single record.
  *
  * @param \MongoDB\BSON\ObjectID $id The ID of the message to delete
  * @throws Swift_IoException
  */
 protected function delete(\MongoDB\BSON\ObjectID $id)
 {
     $bulk = new MongoDB\Driver\BulkWrite();
     $bulk->delete(array('_id' => $id), self::$limit1);
     $this->write($bulk);
 }