當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Server::executeCommand方法代碼示例

本文整理匯總了PHP中MongoDB\Driver\Server::executeCommand方法的典型用法代碼示例。如果您正苦於以下問題:PHP Server::executeCommand方法的具體用法?PHP Server::executeCommand怎麽用?PHP Server::executeCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MongoDB\Driver\Server的用法示例。


在下文中一共展示了Server::executeCommand方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return array|object Command result document
  */
 public function execute(Server $server)
 {
     $cursor = $server->executeCommand($this->databaseName, new Command(['dropDatabase' => 1]));
     if (isset($this->options['typeMap'])) {
         $cursor->setTypeMap($this->options['typeMap']);
     }
     return current($cursor->toArray());
 }
開發者ID:alcaeus,項目名稱:mongo-php-library,代碼行數:15,代碼來源:DropDatabase.php

示例2: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return integer
  */
 public function execute(Server $server)
 {
     $readPreference = isset($this->options['readPreference']) ? $this->options['readPreference'] : null;
     $cursor = $server->executeCommand($this->databaseName, $this->command, $readPreference);
     if (isset($this->options['typeMap'])) {
         $cursor->setTypeMap($this->options['typeMap']);
     }
     return $cursor;
 }
開發者ID:roquie,項目名稱:mongo-php-library,代碼行數:16,代碼來源:DatabaseCommand.php

示例3: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return array|object Command result document
  */
 public function execute(Server $server)
 {
     $cmd = ['dropIndexes' => $this->collectionName, 'index' => $this->indexName];
     $cursor = $server->executeCommand($this->databaseName, new Command($cmd));
     if (isset($this->options['typeMap'])) {
         $cursor->setTypeMap($this->options['typeMap']);
     }
     return current($cursor->toArray());
 }
開發者ID:sunpaolo,項目名稱:slim3Demo,代碼行數:16,代碼來源:DropIndexes.php

示例4: executeCommand

 /**
  * Create one or more indexes for the collection using the createIndexes
  * command.
  *
  * @param Server $server
  */
 private function executeCommand(Server $server)
 {
     $command = new Command(['createIndexes' => $this->collectionName, 'indexes' => $this->indexes]);
     $cursor = $server->executeCommand($this->databaseName, $command);
     $result = current($cursor->toArray());
     if (empty($result->ok)) {
         throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
     }
 }
開發者ID:zoomcharts,項目名稱:mongodb-php,代碼行數:15,代碼來源:CreateIndexes.php

示例5: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return object Command result document
  */
 public function execute(Server $server)
 {
     $cursor = $server->executeCommand($this->databaseName, new Command(array('drop' => $this->collectionName)));
     $result = current($cursor->toArray());
     if (empty($result->ok)) {
         throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
     }
     return $result;
 }
開發者ID:Kozzi11,項目名稱:mongo-php-library-prototype,代碼行數:16,代碼來源:DropCollection.php

示例6: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  *
  * @param Server $server
  *
  * @return mixed[]
  * @throws UnexpectedValueException if the command response was malformed
  */
 public function execute(Server $server)
 {
     $readPreference = isset($this->options['readPreference']) ? $this->options['readPreference'] : null;
     $cursor = $server->executeCommand($this->databaseName, $this->createCommand($server), $readPreference);
     $result = current($cursor->toArray());
     if (!isset($result->values) || !is_array($result->values)) {
         throw new UnexpectedValueException('distinct command did not return a "values" array');
     }
     return $result->values;
 }
開發者ID:phalcon,項目名稱:incubator,代碼行數:20,代碼來源:Distinct.php

示例7: executeCommand

 /**
  * Returns information for all indexes for this collection using the
  * listIndexes command.
  *
  * @param Server $server
  * @return IndexInfoIteratorIterator
  */
 private function executeCommand(Server $server)
 {
     $cmd = array('listIndexes' => $this->collectionName);
     if (isset($this->options['maxTimeMS'])) {
         $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
     }
     $cursor = $server->executeCommand($this->databaseName, new Command($cmd));
     $cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
     return new IndexInfoIteratorIterator($cursor);
 }
開發者ID:Kozzi11,項目名稱:mongo-php-library-prototype,代碼行數:17,代碼來源:ListIndexes.php

示例8: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return object
  */
 public function execute(Server $server)
 {
     $command = new Command(['group' => ['ns' => $this->collectionName, 'key' => $this->keys, 'initial' => $this->initial, '$reduce' => $this->reduce]]);
     $cursor = $server->executeCommand($this->databaseName, $command);
     // Get first element of iterator
     foreach ($cursor as $result) {
         break;
     }
     return isset($result) ? $result : null;
 }
開發者ID:hardsetting,項目名稱:yii2-mongodb,代碼行數:17,代碼來源:Group.php

示例9: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return mixed[]
  */
 public function execute(Server $server)
 {
     $cursor = $server->executeCommand($this->databaseName, $this->createCommand());
     $result = current($cursor->toArray());
     if (empty($result->ok)) {
         throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
     }
     if (!isset($result->values) || !is_array($result->values)) {
         throw new UnexpectedValueException('distinct command did not return a "values" array');
     }
     return $result->values;
 }
開發者ID:Kozzi11,項目名稱:mongo-php-library-prototype,代碼行數:19,代碼來源:Distinct.php

示例10: executeCommand

 /**
  * Returns information for all collections in this database using the
  * listCollections command.
  *
  * @param Server $server
  *
  * @return CollectionInfoCommandIterator
  */
 private function executeCommand(Server $server)
 {
     $cmd = ['listCollections' => 1];
     if (!empty($this->options['filter'])) {
         $cmd['filter'] = (object) $this->options['filter'];
     }
     if (isset($this->options['maxTimeMS'])) {
         $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
     }
     $cursor = $server->executeCommand($this->databaseName, new Command($cmd));
     $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
     return new CollectionInfoCommandIterator($cursor);
 }
開發者ID:phalcon,項目名稱:incubator,代碼行數:21,代碼來源:ListCollections.php

示例11: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return integer
  */
 public function execute(Server $server)
 {
     $cursor = $server->executeCommand($this->databaseName, $this->createCommand());
     $result = current($cursor->toArray());
     if (empty($result->ok)) {
         throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
     }
     // Older server versions may return a float
     if (!isset($result->n) || !(is_integer($result->n) || is_float($result->n))) {
         throw new UnexpectedValueException('count command did not return a numeric "n" value');
     }
     return (int) $result->n;
 }
開發者ID:Kozzi11,項目名稱:mongo-php-library-prototype,代碼行數:20,代碼來源:Count.php

示例12: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return 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;
     }
     return current($cursor->toArray());
 }
開發者ID:zivperry,項目名稱:mongo-php-library,代碼行數:23,代碼來源:DropCollection.php

示例13: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return object Command result document
  */
 public function execute(Server $server)
 {
     try {
         $cursor = $server->executeCommand($this->databaseName, new Command(array('drop' => $this->collectionName)));
     } catch (DriverRuntimeException $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' => 'ns not found'];
         }
         throw $e;
     }
     $result = current($cursor->toArray());
     if (empty($result->ok)) {
         throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
     }
     return $result;
 }
開發者ID:pkdevbox,項目名稱:mongo-php-library,代碼行數:27,代碼來源:DropCollection.php

示例14: execute

 /**
  * Execute the operation.
  *
  * @see Executable::execute()
  *
  * @param Server $server
  *
  * @return DatabaseInfoIterator
  * @throws UnexpectedValueException if the command response was malformed
  */
 public function execute(Server $server)
 {
     $cmd = ['listDatabases' => 1];
     if (isset($this->options['maxTimeMS'])) {
         $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
     }
     $cursor = $server->executeCommand('admin', new Command($cmd));
     $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
     $result = current($cursor->toArray());
     if (!isset($result['databases']) || !is_array($result['databases'])) {
         throw new UnexpectedValueException('listDatabases command did not return a "databases" array');
     }
     /* Return an Iterator instead of an array in case listDatabases is
      * eventually changed to return a command cursor, like the collection
      * and index enumeration commands. This makes the "totalSize" command
      * field inaccessible, but users can manually invoke the command if they
      * need that value.
      */
     return new DatabaseInfoLegacyIterator($result['databases']);
 }
開發者ID:phalcon,項目名稱:incubator,代碼行數:30,代碼來源:ListDatabases.php

示例15: executeCommand

 /**
  * Returns information for all indexes for this collection using the
  * listIndexes command.
  *
  * @param Server $server
  * @return IndexInfoIteratorIterator
  */
 private function executeCommand(Server $server)
 {
     $cmd = ['listIndexes' => $this->collectionName];
     if (isset($this->options['maxTimeMS'])) {
         $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
     }
     try {
         $cursor = $server->executeCommand($this->databaseName, new Command($cmd));
     } catch (RuntimeException $e) {
         /* The server may return an error if the collection does not exist.
          * Check for possible error codes (see: SERVER-20463) and return an
          * empty iterator instead of throwing.
          */
         if ($e->getCode() === self::$errorCodeNamespaceNotFound || $e->getCode() === self::$errorCodeDatabaseNotFound) {
             return new IndexInfoIteratorIterator(new EmptyIterator());
         }
         throw $e;
     }
     $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
     return new IndexInfoIteratorIterator($cursor);
 }
開發者ID:TheManagers,項目名稱:mongo-php-library,代碼行數:28,代碼來源:ListIndexes.php


注:本文中的MongoDB\Driver\Server::executeCommand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。