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


PHP MongoCursor类代码示例

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


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

示例1: __construct

 /**
  * The cursor constructor
  * @param string|EMongoDocument $modelClass - The class name for the active record
  * @param array|MongoCursor|EMongoCriteria $criteria -  Either a condition array (without sort,limit and skip) or a MongoCursor Object
  * @param array $fields
  */
 public function __construct($modelClass, $criteria = array(), $fields = array())
 {
     // If $fields has something in it
     if (!empty($fields)) {
         $this->partial = true;
     }
     if (is_string($modelClass)) {
         $this->modelClass = $modelClass;
         $this->model = EMongoDocument::model($this->modelClass);
     } elseif ($modelClass instanceof EMongoDocument) {
         $this->modelClass = get_class($modelClass);
         $this->model = $modelClass;
     }
     if ($criteria instanceof MongoCursor) {
         $this->cursor = $criteria;
         $this->cursor->reset();
     } elseif ($criteria instanceof EMongoCriteria) {
         $this->criteria = $criteria;
         $this->cursor = $this->model->getCollection()->find($criteria->condition, $criteria->project)->sort($criteria->sort);
         if ($criteria->skip > 0) {
             $this->cursor->skip($criteria->skip);
         }
         if ($criteria->limit > 0) {
             $this->cursor->limit($criteria->limit);
         }
     } else {
         // Then we are doing an active query
         $this->criteria = $criteria;
         $this->cursor = $this->model->getCollection()->find($criteria, $fields);
     }
 }
开发者ID:pvassiliou,项目名称:MongoYii,代码行数:37,代码来源:EMongoCursor.php

示例2: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $mongoDbName = $input->getArgument('mongo-db');
     $mongoCollectionName = $input->getArgument('mongo-collection');
     $mongoHost = $input->getArgument('mongo-host');
     $mongoPort = $input->getArgument('mongo-port');
     $mongoUserName = $input->getOption('mongo-user');
     $mongoPassword = $input->getOption('mongo-password');
     $options = array();
     if (!empty($mongoUserName)) {
         $options['username'] = $mongoUserName;
     }
     if (!empty($mongoPassword)) {
         $options['password'] = $mongoPassword;
     }
     $m = new MongoClient("mongodb://{$mongoHost}:{$mongoPort}", $options);
     $db = $m->{$mongoDbName};
     \MongoCursor::$timeout = -1;
     $output->writeln("Connected to the database <info>{$mongoDbName}</info>");
     $collection = $db->{$mongoCollectionName};
     $cursor = $this->getCursor($collection);
     $i = 0;
     $output->writeln("Removing elastic-search index...");
     $this->doDeleteIndex($input, $output);
     $output->writeln("Creating elastic-search index...");
     $this->doCreateIndex($input, $output);
     $output->writeln("Setting-up elastic-search mapping...");
     $this->doSetupMapping($input, $output);
     $output->writeln("\nIndexing...");
     $guzzle = $this->getGuzzle($input);
     $flag = 0;
     $nbEntries = $cursor->count(true);
     $timeStart = microtime(true);
     $requests = array();
     while ($flag == 0) {
         try {
             foreach ($cursor as $obj) {
                 $i++;
                 unset($obj['_id']);
                 $requests[] = $guzzle->put($input->getArgument('es-type') . '/' . $i, null, json_encode($obj));
                 if (0 === $i % 180) {
                     $guzzle->send($requests);
                     $requests = array();
                 }
                 if (0 === $i % 10000) {
                     $elapsedTime = microtime(true) - $timeStart;
                     $entriesPerSeconds = floor($i / $elapsedTime);
                     $output->writeln(date('H:i:s') . "\tProgress: {$i}/{$nbEntries}\t({$entriesPerSeconds}/seconds)\t" . round($i / $nbEntries * 100) . "% \t" . "~" . $this->secsToString(($nbEntries - $i) / $entriesPerSeconds) . " left\tMemory usage : " . (memory_get_usage() >> 20) . "Mo");
                 }
             }
             $flag = 1;
         } catch (Exception $ex) {
             $output->writeln("Something went wrong within MongoDB: " . $ex->getMessage() . ", Retrying ...");
             $flag = 0;
             $cursor = getCursor($collection);
         }
     }
     $output->writeln("{$i} entries processed. Took " . $this->secsToString(floor(microtime(true) - $timeStart)) . " seconds");
     return 0;
 }
开发者ID:aztech-dev,项目名称:GeonamesServer,代码行数:60,代码来源:DoIndexCommand.php

示例3: limit

 public function limit($itemCountPerPage)
 {
     if ($this->resource instanceof \MongoCursor) {
         return $this->resource->limit($itemCountPerPage);
     }
     return $this->resource;
 }
开发者ID:pasechnik,项目名称:mongozend,代码行数:7,代码来源:Result.php

示例4: count

 /**
  * Count the results from the query
  *
  * + Count the results from the current query: pass false for "all" results (disregard limit/skip)
  * + Count results of a separate query: pass an array or JSON string of query parameters
  *
  * @since   0.3.0
  *
  * See [\Countable::count]
  *
  * @link    http://www.php.net/manual/en/mongocursor.count.php \MongoCursor::count
  *
  * @param   boolean|array|string  $query
  *
  * @return  integer
  *
  * @throws  \Exception
  *
  * @uses    \JSON::encodeMongo
  * @uses    \JSON::decode
  * @uses    \Profiler::start
  * @uses    \Profiler::stop
  */
 public function count($query = true)
 {
     if (is_bool($query)) {
         // Profile count operation for cursor
         if ($this->getClientInstance()->profiling) {
             $this->benchmark = Profiler::start(get_class($this->getClientInstance()) . "::{$this->db}", $this->shellQuery() . ".count(" . JSON::encodeMongo($query) . ")");
         }
         $this->cursor || $this->load();
         $count = $this->cursor->count($query);
     } else {
         if (is_string($query) && $query[0] == "{") {
             $query = JSON::decode($query, true);
         }
         $query_trans = array();
         foreach ($query as $field => $value) {
             $query_trans[$this->getFieldName($field)] = $value;
         }
         $query = $query_trans;
         // Profile count operation for collection
         if ($this->getClientInstance()->profiling) {
             $this->benchmark = Profiler::start(get_class($this->getClientInstance()) . "::{$this->db}", "db.{$this->name}.count(" . ($query ? JSON::encodeMongo($query) : '') . ")");
         }
         $count = $this->getCollection()->count($query);
     }
     // End profiling count
     if ($this->benchmark) {
         // Stop the benchmark
         Profiler::stop($this->benchmark);
         // Clean benchmark token
         $this->benchmark = null;
     }
     return $count;
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:56,代码来源:Collection.php

示例5: mapReduce

 /**
  * run the map/reduce
  * @static
  * @return void
  */
 public static function mapReduce()
 {
     $map = "function () {\r\n            if(arguments.callee.shipcache === undefined)\r\n            {\r\n                arguments.callee.shipcache = {}\r\n            }\r\n            if(arguments.callee.shipcache[this.victim.shipTypeID] === undefined)\r\n            {\r\n                arguments.callee.shipcache[this.victim.shipTypeID] = db.Kingboard_EveItem.findOne({typeID: parseInt(this.victim.shipTypeID)},{'marketGroup.parentGroup.marketGroupName':1});\r\n            }\r\n            var ship = arguments.callee.shipcache[this.victim.shipTypeID];\r\n            var info = {}\r\n            info[this.victim.shipType] = 1;\r\n            info[\"total\"] = 1;\r\n            if(ship != null && ship.marketGroup != null)\r\n                emit(ship.marketGroup.parentGroup.marketGroupName, info);\r\n        }";
     $reduce = "function (k, vals) {\r\n            var sums = {}\r\n            var total = 0;\r\n            vals.forEach(function(info) {\r\n                info[\"total\"] = 0;\r\n                for (var key in info)\r\n                {\r\n                    if(sums[key] === undefined)\r\n                        sums[key] = 0;\r\n                    sums[key] += info[key];\r\n                    total += info[key];\r\n                }\r\n            });\r\n            sums[\"total\"] = total;\r\n            return sums;\r\n        }";
     // we want the map/reduce to run for as long as it takes
     MongoCursor::$timeout = -1;
     return King23_Mongo::mapReduce("Kingboard_Kill", __CLASS__, $map, $reduce);
 }
开发者ID:holdensmagicalunicorn,项目名称:Kingboard,代码行数:13,代码来源:Kingboard_Kill_MapReduce_KillsByShip.php

示例6: getCursorFromQueryLog

 /**
  * Create MongoCursor from string query log
  *
  * @param string $queryString
  * @return \MongoCursor|null
  */
 protected function getCursorFromQueryLog($queryString)
 {
     $cursor = null;
     $connection = $this->panel->getDb();
     $connection->open();
     if ($connection->isActive) {
         $queryInfo = Json::decode($queryString);
         $query = $this->prepareQuery(isset($queryInfo['query']['$query']) ? $queryInfo['query']['$query'] : $queryInfo['query']);
         $cursor = new \MongoCursor($connection->mongoClient, $queryInfo['ns'], $query, $queryInfo['fields']);
         $cursor->limit($queryInfo['limit']);
         $cursor->skip($queryInfo['skip']);
         if (isset($queryInfo['query']['$orderby'])) {
             $cursor->sort($queryInfo['query']['$orderby']);
         }
     }
     return $cursor;
 }
开发者ID:miradnan,项目名称:yii2-mongodb,代码行数:23,代码来源:ExplainAction.php

示例7: __construct

 /**
  * 
  * @param \MongoDb $db
  * @param \Mongodloid_Connection $connection
  */
 public function __construct(\MongoDb $db, \Mongodloid_Connection $connection)
 {
     parent::__construct($db, $connection);
     $this->collections = Billrun_Factory::config()->getConfigValue('db.collections', array());
     $timeout = Billrun_Factory::config()->getConfigValue('db.timeout', 3600000);
     // default 60 minutes
     Billrun_Factory::log()->log('Set database cursor timeout to: ' . $timeout, Zend_Log::INFO);
     MongoCursor::$timeout = $timeout;
 }
开发者ID:kalburgimanjunath,项目名称:system,代码行数:14,代码来源:Db.php

示例8: getCollection

 public function getCollection($collectionName)
 {
     MongoCursor::$slaveOkay = true;
     //if empty($this->dbName) throw error;
     $dbName = $this->dbName;
     Yii::import('application.extensions.mp.db.mongodb.*');
     $this->_collection = new MongoMSCollection($this->_writeServer->{$dbName}, $collectionName);
     $this->_collection->addSlaves($this->_readServers);
     return $this->_collection;
 }
开发者ID:hukumonline,项目名称:yii,代码行数:10,代码来源:MPMongoDbManager.php

示例9: getNext

 /**
  * Retrieve the collection object (as provided by x::find())
  * @return Collection
  */
 public function getNext()
 {
     $item = $this->cursor->getNext();
     $obj = clone $this->collection;
     $obj->populate($item);
     return $obj;
 }
开发者ID:rogerthomas84,项目名称:ohdm,代码行数:11,代码来源:Cursor.php

示例10: sort

 public function sort($fields)
 {
     if ($this->count() > 1) {
         $this->cursor->sort($fields);
     }
     return $this;
 }
开发者ID:irto,项目名称:neomongo,代码行数:7,代码来源:OdmCursor.php

示例11: getReadPreference

 public function getReadPreference()
 {
     if ($this->cursor) {
         return $this->cursor->getReadPreference();
     }
     return $this->readPreference;
 }
开发者ID:paulocarvalhodesign,项目名称:php-mongo,代码行数:7,代码来源:Cursor.php

示例12: current

 /**
  * Returns the current element
  * 
  * @return array|object
  */
 public function current()
 {
     $values = parent::current();
     if (isset($values) && isset($this->collection) && $this->collection->getDocumentClass()) {
         $values = $this->collection->asDocument($values, $this->lazy);
     }
     return $values;
 }
开发者ID:jasny,项目名称:db-mongo,代码行数:13,代码来源:Cursor.php

示例13: testDelete

 public function testDelete()
 {
     $filename = 'tests/Formelsamling.pdf';
     $id = $this->object->put($filename);
     $this->object->delete($id);
     $file = $this->object->get($id);
     $this->assertNull($file);
 }
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:8,代码来源:MongoGridFSTest.php

示例14: current

 public function current()
 {
     if ($this->collectionName === null) {
         return new $this->objectType(parent::current());
     } else {
         return new $this->objectType($this->collectionName, parent::current());
     }
 }
开发者ID:photon,项目名称:storage-mongodb-object,代码行数:8,代码来源:ObjectIterator.php

示例15: calculateTotalItemCount

 /**
  * @see CActiveDataProvider::calculateTotalItemCount()
  * @return int
  */
 public function calculateTotalItemCount()
 {
     if (!$this->_builder) {
         $criteria = $this->getCriteria();
         $this->_builder = new EMongoQueryBuilder($this->model, isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : []);
     }
     return $this->_builder->count();
 }
开发者ID:yiicod,项目名称:mongoyii,代码行数:12,代码来源:EMongoDataProvider.php


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