当前位置: 首页>>代码示例>>PHP>>正文


PHP MongoDB::command方法代码示例

本文整理汇总了PHP中MongoDB::command方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoDB::command方法的具体用法?PHP MongoDB::command怎么用?PHP MongoDB::command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDB的用法示例。


在下文中一共展示了MongoDB::command方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getUser

 /**
  * Communicates with the database to log in a user.
  * 
  * @param MongoDB $db       database
  * @param string  $username username
  * @param string  $pwd      plaintext password
  *
  * @return array the database response
  */
 protected static function getUser($db, $username, $pwd)
 {
     $ns = "{$db}.system.users";
     // get the nonce
     $result = $db->command(array(MongoUtil::NONCE => 1));
     if (!$result["ok"]) {
         return $result;
     }
     $nonce = $result["nonce"];
     // create a digest of nonce/username/pwd
     $digest = md5($nonce . $username . $pwd);
     $data = array(MongoUtil::AUTHENTICATE => 1, "user" => $username, "nonce" => $nonce, "key" => $digest);
     // send everything to the db and pray
     return $db->command($data);
 }
开发者ID:kph11,项目名称:mongo-php-driver,代码行数:24,代码来源:Auth.php

示例2: getTags

 /**
  * Return an array of stored tags
  *
  * @return array array of stored tags (string)
  */
 public function getTags()
 {
     $cmd['mapreduce'] = $this->_options['collection'];
     $cmd['map'] = 'function(){
                             this.t.forEach(
                                 function(z){
                                     emit( z , { count : 1 } );
                                 }
                             );
                         };';
     $cmd['reduce'] = 'function( key , values ){
                             var total = 0;
                             for ( var i=0; i<values.length; i++ )
                                 total += values[i].count;
                             return { count : total };
                         };';
     $cmd['out'] = array('replace' => 'getTagsCollection');
     $res2 = $this->_db->command($cmd);
     $res3 = $this->_db->selectCollection('getTagsCollection')->find();
     $res = array();
     foreach ($res3 as $key => $val) {
         $res[] = $key;
     }
     $this->_db->dropCollection($res2['result']);
     return $res;
 }
开发者ID:TerranetMD,项目名称:zf-cache-backend,代码行数:31,代码来源:Mongo.php

示例3: command

 /**
  * command.
  */
 public function command($command, array $options = array(), &$hash = NULL)
 {
     $this->time->start();
     $return = parent::command($command, $options);
     $time = $this->time->stop();
     $this->log(array('type' => 'command', 'options' => $options, 'time' => $time));
     return $return;
 }
开发者ID:mongator,项目名称:mongator,代码行数:11,代码来源:LoggableMongoDB.php

示例4: command

 /**
  * command.
  */
 public function command($data)
 {
     $this->time->start();
     $return = parent::command($data);
     $time = $this->time->stop();
     $this->log(array('type' => 'command', 'data' => $data, 'time' => $time));
     return $return;
 }
开发者ID:robo47,项目名称:mandango,代码行数:11,代码来源:LoggableMongoDB.php

示例5: command

 /**
  * Wrapper method for MongoDB::command().
  *
  * @see http://php.net/manual/en/mongodb.command.php
  * @param array  $command Command document
  * @param array  $options Client-side options (e.g. socket timeout)
  * @param string $hash    Optional reference argument to collect the server
  *                        hash for command cursors (for driver 1.5+ only)
  * @return array
  */
 public function command(array $command, array $options = [], &$hash = null)
 {
     $options = isset($options['timeout']) ? $this->convertSocketTimeout($options) : $options;
     if (func_num_args() > 2) {
         return $this->mongoDB->command($command, $options, $hash);
     }
     return $this->mongoDB->command($command, $options);
 }
开发者ID:alcaeus,项目名称:mongodb,代码行数:18,代码来源:Database.php

示例6: command

 /**
  * Command.
  *
  * Runs a MongoDB command (such as GeoNear). See the MongoDB documentation
  *  for more usage scenarios - http://dochub.mongodb.org/core/commands
  *
  * @param array $query The command query
  *
  * @access public
  * @return \MongoQB\Builder
  */
 public function command($query = array())
 {
     try {
         $execute = $this->_dbhandle->command($query);
         return $execute;
     } catch (\MongoCursorException $Exception) {
         throw new \MongoQB\Exception('MongoDB command failed to execute: ' . $Exception->getMessage());
         // @codeCoverageIgnoreEnd
     }
 }
开发者ID:aodto,项目名称:mongoqb,代码行数:21,代码来源:Builder.php

示例7: distinct

 /**
  * Distinct
  * Select distinct from collection
  * @param array $query The search query
  * @param string $distinct The collection name
  * @access public
  * @return \MongoQB\Builder
  */
 public function distinct($distinct = "", $key = "", $query = array())
 {
     try {
         $query = array('distinct' => $distinct, 'key' => $key, 'query' => $query);
         $execute = $this->_dbhandle->command($query);
         return isset($execute['values']) ? $execute['values'] : false;
     } catch (\MongoCursorException $Exception) {
         throw new Exception('MongoDB command failed to execute: ' . $Exception->getMessage());
         // @codeCoverageIgnoreEnd
     }
 }
开发者ID:enkindle,项目名称:JumpSeat,代码行数:19,代码来源:Mongo_db.php

示例8: testDBCommand

 public function testDBCommand()
 {
     $x = $this->object->command(array());
     $this->assertEquals(0, strpos($x['errmsg'], "no such cmd"), json_encode($x));
     $this->assertEquals((bool) $x['ok'], false);
     $created = $this->object->createCollection("system.profile", true, 5000);
     $this->object->command(array('profile' => 0));
     $x = $this->object->command(array('profile' => 1));
     $this->assertEquals($x['was'], 0, json_encode($x));
     $this->assertEquals((bool) $x['ok'], true, json_encode($x));
 }
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:11,代码来源:MongoDBTest.php

示例9: group

 /**
  * Performs an operation similar to SQL's GROUP BY command
  *
  * @param mixed $keys - Fields to group by. If an array or non-code
  *   object is passed, it will be the key used to group results.
  * @param array $initial - Initial value of the aggregation counter
  *   object.
  * @param mongocode $reduce - A function that takes two arguments (the
  *   current document and the aggregation to this point) and does the
  *   aggregation.
  * @param array $options - Optional parameters to the group command
  *
  * @return array - Returns an array containing the result.
  */
 public function group($keys, array $initial, $reduce, array $options = array())
 {
     $cmd = ['group' => ['ns' => $this->name, 'key' => $keys, '$reduce' => $reduce, 'initial' => $initial]];
     if (isset($options['finalize'])) {
         $cmd['group']['finalize'] = $options['finalize'];
     }
     if (isset($options['condition'])) {
         $cmd['group']['cond'] = $options['condition'];
     }
     return $this->db->command($cmd);
 }
开发者ID:Maslosoft,项目名称:mongofill,代码行数:25,代码来源:MongoCollection.php

示例10: getTableStats

 /**
  * @param string $table
  * @return array
  */
 public function getTableStats($table)
 {
     $stats = array();
     if (!$this->collectionExists($table)) {
         return $stats;
     }
     $rawstats = $this->dbcon->command(array('collStats' => $table));
     $stats['rows'] = $rawstats['count'];
     if ($table = TeraWurflConfig::$TABLE_PREFIX . 'Merge') {
         $collection = $this->dbcon->selectCollection($table);
         $tofind = array('actual_device_root' => 1);
         $res = $collection->find($tofind);
         $stats['actual_devices'] = $res->count();
     }
     $stats['bytesize'] = $rawstats['storageSize'];
     return $stats;
 }
开发者ID:vallejos,项目名称:samples,代码行数:21,代码来源:TeraWurflDatabase_MongoDB.php

示例11: aggregate

 /**
  * @link http://www.php.net/manual/en/mongocollection.aggregate.php
  * @param array $pipeline
  * @param array $op
  * @return array
  */
 public function aggregate(array $pipeline, array $op = [])
 {
     if (!TypeConverter::isNumericArray($pipeline)) {
         $pipeline = [];
         $options = [];
         $i = 0;
         foreach (func_get_args() as $operator) {
             $i++;
             if (!is_array($operator)) {
                 trigger_error("Argument {$i} is not an array", E_WARNING);
                 return;
             }
             $pipeline[] = $operator;
         }
     } else {
         $options = $op;
     }
     $command = ['aggregate' => $this->name, 'pipeline' => $pipeline];
     $command += $options;
     return $this->db->command($command, [], $hash);
 }
开发者ID:RageZBla,项目名称:mongo-php-adapter,代码行数:27,代码来源:MongoCollection.php

示例12: group

 /**
  * Performs an operation similar to SQL's GROUP BY command
  *
  * @link http://www.php.net/manual/en/mongocollection.group.php
  * @param mixed $keys Fields to group by. If an array or non-code object is passed, it will be the key used to group results.
  * @param array $initial Initial value of the aggregation counter object.
  * @param MongoCode|string $reduce A function that aggregates (reduces) the objects iterated.
  * @param array $condition An condition that must be true for a row to be considered.
  * @return array
  */
 public function group($keys, array $initial, $reduce, array $condition = [])
 {
     if (is_string($reduce)) {
         $reduce = new MongoCode($reduce);
     }
     $command = ['group' => ['ns' => $this->name, '$reduce' => (string) $reduce, 'initial' => $initial, 'cond' => $condition]];
     if ($keys instanceof MongoCode) {
         $command['group']['$keyf'] = (string) $keys;
     } else {
         $command['group']['key'] = $keys;
     }
     if (array_key_exists('condition', $condition)) {
         $command['group']['cond'] = $condition['condition'];
     }
     if (array_key_exists('finalize', $condition)) {
         if ($condition['finalize'] instanceof MongoCode) {
             $condition['finalize'] = (string) $condition['finalize'];
         }
         $command['group']['finalize'] = $condition['finalize'];
     }
     return $this->db->command($command);
 }
开发者ID:icatholic,项目名称:mongo-php-adapter,代码行数:32,代码来源:MongoCollection.php

示例13: returnsDistinct

 public function returnsDistinct(ObjectModel\Collection $collection, ObjectModel\Property\PropertyAbstract $property)
 {
     $class = $collection->getDataObject()->getClass();
     $mode = $collection->getParameter('memberType');
     // set database to use
     $this->_selectDatabase();
     // get collection to use, from mapper if available, else from data object
     $collec = $this->_mapper instanceof Backend\Mapper ? $this->_mapper->getDatastore($class) : $class;
     //$collec = $this->_db->selectCollection($collec);
     $conditions = array();
     /* @var $condition t41_Condition */
     foreach ($collection->getConditions() as $conditionArray) {
         $condition = $conditionArray[0];
         // map property to field
         if ($this->_mapper) {
             $field = $this->_mapper->propertyToDatastoreName($class, $condition->getProperty()->getId());
         } else {
             $field = $condition->getProperty()->getId();
         }
         $conditions += $this->_buildConditionStatement($field, $condition->getClauses(), $conditions);
         switch ($conditionArray[1]) {
             case 'OR':
                 //$select->orWhere($statement);
                 break;
             case 'AND':
             default:
                 //$select->where($statement);
                 break;
         }
     }
     $params = array();
     $params['distinct'] = $collec;
     $params['key'] = $property->getId();
     $params['query'] = $conditions;
     $this->_setLastQuery('command', $params);
     $ids = $this->_db->command($params);
     /* @todo if property is an object, we should get all values from the list of ids */
     return isset($ids['values']) ? $ids['values'] : array();
 }
开发者ID:crapougnax,项目名称:t41,代码行数:39,代码来源:MongoDBAdapter.php

示例14: info

 /**
  * read collection information
  *
  * @param MongoDB $db database
  * @param string $collection collection name
  */
 public static function info(MongoDB $db, $collection)
 {
     $ret = $db->command(array("collStats" => $collection));
     if (!$ret["ok"]) {
         exit("There is something wrong:<font color=\"red\">{$ret['errmsg']}</font>, please refresh the page to try again.");
     }
     if (!isset($ret["retval"]["options"])) {
         $ret["retval"]["options"] = array();
     }
     $isCapped = 0;
     $size = 0;
     $max = 0;
     $options = $ret["retval"]["options"];
     if (isset($options["capped"])) {
         $isCapped = $options["capped"];
     }
     if (isset($options["size"])) {
         $size = $options["size"];
     }
     if (isset($options["max"])) {
         $max = $options["max"];
     }
     return array("capped" => $isCapped, "size" => $size, "max" => $max);
 }
开发者ID:boosen,项目名称:rockmongo,代码行数:30,代码来源:MCollection.php

示例15: setProfiler

 /**
  * Set MongoDb profiler
  *
  * @param int $level 0, 1, 2
  * @param int $slowms slow queries in ms.
  * @return array
  */
 public function setProfiler($level = self::PROFILE_ALL, $slowms = 100)
 {
     return $this->db->command(['profile' => (int) $level, 'slowms' => (int) $slowms]);
 }
开发者ID:stanislav-web,项目名称:PhalconSonar,代码行数:11,代码来源:AbstractMongoMapper.php


注:本文中的MongoDB::command方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。