php MongoDB-Driver-Server类(方法)实例源码

下面列出了php MongoDB-Driver-Server 类(方法)源码代码实例,从而了解它的用法。

作者:Kozzi1    项目:mongo-php-library-prototyp   
/**
 * Return whether the server supports a particular feature.
 *
 * @internal
 * @param Server  $server  Server to check
 * @param integer $feature Feature constant (i.e. wire protocol version)
 * @return boolean
 */
function server_supports_feature(Server $server, $feature)
{
    $info = $server->getInfo();
    $maxWireVersion = isset($info['maxWireVersion']) ? (int) $info['maxWireVersion'] : 0;
    $minWireVersion = isset($info['minWireVersion']) ? (int) $info['minWireVersion'] : 0;
    return $minWireVersion <= $feature && $maxWireVersion >= $feature;
}

作者:Kozzi1    项目:mongo-php-library-prototyp   
/**
  * Returns information for all indexes for this collection by querying the
  * "system.indexes" collection (MongoDB <3.0).
  *
  * @param Server $server
  * @return IndexInfoIteratorIterator
  */
 private function executeLegacy(Server $server)
 {
     $filter = array('ns' => $this->databaseName . '.' . $this->collectionName);
     $options = isset($this->options['maxTimeMS']) ? array('modifiers' => array('$maxTimeMS' => $this->options['maxTimeMS'])) : array();
     $cursor = $server->executeQuery($this->databaseName . '.system.indexes', new Query($filter, $options));
     $cursor->setTypeMap(array('root' => 'array', 'document' => 'array'));
     return new IndexInfoIteratorIterator($cursor);
 }

作者:alcaeu    项目:mongo-php-librar   
/**
  * 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());
 }

作者:zivperr    项目:mongo-php-librar   
/**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return DeleteResult
  */
 public function execute(Server $server)
 {
     $bulk = new Bulk();
     $bulk->delete($this->filter, ['limit' => $this->limit]);
     $writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
     $writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
     return new DeleteResult($writeResult);
 }

作者:roqui    项目:mongo-php-librar   
/**
  * 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;
 }

作者:Kozzi1    项目:mongo-php-library-prototyp   
/**
  * 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;
 }

作者:sunpaol    项目:slim3Dem   
/**
  * 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());
 }

作者:hardsettin    项目:yii2-mongod   
/**
  * 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;
 }

作者:phalco    项目:incubato   
/**
  * 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;
 }

作者:dangchen    项目:mongo-php-librar   
/**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return InsertOneResult
  */
 public function execute(Server $server)
 {
     $bulk = new Bulk();
     $insertedId = $bulk->insert($this->document);
     if ($insertedId === null) {
         // TODO: This may be removed if PHPC-382 is implemented
         $insertedId = is_array($this->document) ? $this->document['_id'] : $this->document->_id;
     }
     $writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
     $writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
     return new InsertOneResult($writeResult, $insertedId);
 }

作者:Kozzi1    项目:mongo-php-library-prototyp   
/**
  * 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;
 }

作者:Kozzi1    项目:mongo-php-library-prototyp   
/**
  * 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;
 }

作者:zivperr    项目:mongo-php-librar   
/**
  * 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());
 }

作者:pkdevbo    项目:mongo-php-librar   
/**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return UpdateResult
  */
 public function execute(Server $server)
 {
     $options = array('multi' => $this->options['multi'], 'upsert' => $this->options['upsert']);
     $bulk = new Bulk();
     $bulk->update($this->filter, $this->update, $options);
     $writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
     $writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
     return new UpdateResult($writeResult);
 }

作者:zivperr    项目:mongo-php-librar   
/**
  * 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->createCommand(), $readPreference);
     $result = current($cursor->toArray());
     // 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;
 }

作者:pkdevbo    项目:mongo-php-librar   
/**
  * 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;
 }

作者:phalco    项目:incubato   
/**
  * 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']);
 }

作者:dangchen    项目:mongo-php-librar   
/**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return InsertManyResult
  */
 public function execute(Server $server)
 {
     $bulk = new Bulk(['ordered' => $this->options['ordered']]);
     $insertedIds = [];
     foreach ($this->documents as $i => $document) {
         $insertedId = $bulk->insert($document);
         if ($insertedId !== null) {
             $insertedIds[$i] = $insertedId;
         } else {
             // TODO: This may be removed if PHPC-382 is implemented
             $insertedIds[$i] = is_array($document) ? $document['_id'] : $document->_id;
         }
     }
     $writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
     $writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
     return new InsertManyResult($writeResult, $insertedIds);
 }

作者:dangchen    项目:mongo-php-librar   
/**
  * Execute the operation.
  *
  * @see Executable::execute()
  * @param Server $server
  * @return BulkWriteResult
  */
 public function execute(Server $server)
 {
     $bulk = new Bulk(['ordered' => $this->options['ordered']]);
     $insertedIds = [];
     foreach ($this->operations as $i => $operation) {
         $type = key($operation);
         $args = current($operation);
         switch ($type) {
             case self::DELETE_MANY:
             case self::DELETE_ONE:
                 $bulk->delete($args[0], $args[1]);
                 break;
             case self::INSERT_ONE:
                 $insertedId = $bulk->insert($args[0]);
                 if ($insertedId !== null) {
                     $insertedIds[$i] = $insertedId;
                 } else {
                     // TODO: This may be removed if PHPC-382 is implemented
                     $insertedIds[$i] = is_array($args[0]) ? $args[0]['_id'] : $args[0]->_id;
                 }
                 break;
             case self::REPLACE_ONE:
             case self::UPDATE_MANY:
             case self::UPDATE_ONE:
                 $bulk->update($args[0], $args[1], $args[2]);
         }
     }
     $writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
     $writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
     return new BulkWriteResult($writeResult, $insertedIds);
 }

作者:Kozzi1    项目:mongo-php-library-prototyp   
/**
  * Create one or more indexes for the collection by inserting into the
  * "system.indexes" collection (MongoDB <2.6).
  *
  * @param Server $server
  * @param IndexInput[] $indexes
  */
 private function executeLegacy(Server $server)
 {
     $bulk = new Bulk(true);
     foreach ($this->indexes as $index) {
         $bulk->insert($index);
     }
     $server->executeBulkWrite($this->databaseName . '.system.indexes', $bulk);
 }


问题


面经


文章

微信
公众号

扫码关注公众号