Phalcon\Db\Adapter\MongoDB\Operation\DropCollection::execute PHP Метод

execute() публичный Метод

Execute the operation.
См. также: Executable::execute()
public execute ( MongoDB\Driver\Server $server ) : array | object
$server MongoDB\Driver\Server
Результат array | object Command result document
    public function execute(Server $server)
    {
        try {
            $cursor = $server->executeCommand($this->databaseName, new Command(['drop' => $this->collectionName]));
        } catch (RuntimeException $e) {
            /* The server may return an error if the collection does not exist.
             * Check for an error message (unfortunately, there isn't a code)
             * and NOP instead of throwing.
             */
            if ($e->getMessage() === self::$errorMessageNamespaceNotFound) {
                return (object) ['ok' => 0, 'errmsg' => self::$errorMessageNamespaceNotFound];
            }
            throw $e;
        }
        if (isset($this->options['typeMap'])) {
            $cursor->setTypeMap($this->options['typeMap']);
        }
        return current($cursor->toArray());
    }

Usage Example

Пример #1
0
 /**
  * Drop this collection.
  *
  * @see DropCollection::__construct() for supported options
  *
  * @param array $options Additional options
  *
  * @return array|object Command result document
  */
 public function drop(array $options = [])
 {
     if (!isset($options['typeMap'])) {
         $options['typeMap'] = $this->typeMap;
     }
     $operation = new DropCollection($this->databaseName, $this->collectionName, $options);
     $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
     return $operation->execute($server);
 }