當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。