• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP MongoCursor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了MongoCursor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: testExceptionHost

 public function testExceptionHost()
 {
     $host = "";
     $this->object->insert(array("_id" => 1), array("safe" => true));
     try {
         $this->object->insert(array("_id" => 1), array("safe" => true));
     } catch (MongoCursorException $e) {
         $host = $e->getHost();
     }
     $this->assertEquals("localhost:27017", $host);
 }
开发者ID:kph11,项目名称:mongo-php-driver,代码行数:11,代码来源:MongoCursorTest.php


示例10: fetch

 public function fetch($key, &$value, $timeout_version = null)
 {
     MongoCursor::$slaveOkay = true;
     $store = self::$_mongodb->findOne(array('key' => $this->create_key($key)));
     if (!is_null($store) && $timeout_version < $store['dateline']) {
         if ($store['ttl'] > 0 && $store['dateline'] + $store['ttl'] < time()) {
             return false;
         }
         $value = $store['value'];
         return true;
     }
     return false;
 }
开发者ID:sss201413,项目名称:ecstore,代码行数:13,代码来源:mongodb.php


示例11: testTimeout3

 public function testTimeout3()
 {
     for ($i = 0; $i < 10000; $i++) {
         $this->object->insert(array("name" => "joe" . $i, "interests" => array(rand(), rand(), rand())));
     }
     $cmd = $this->object->db->selectCollection('$cmd');
     $query = 'r = 0; cursor = db.c.find(); while (cursor.hasNext()) { x = cursor.next(); for (i=0; i<200; i++) { if (x.name == "joe"+i) { r++; } } } return r;';
     $count = 0;
     for ($i = 0; $i < 3; $i++) {
         $cursor = $cmd->find(array('$eval' => $query))->limit(-1)->timeout(500);
         try {
             $x = $cursor->getNext();
             $this->assertFalse(true, json_encode($x));
         } catch (MongoCursorTimeoutException $e) {
             $count++;
         }
     }
     $this->assertEquals(3, $count);
     $x = $this->object->findOne();
     $this->assertNotNull($x);
     $this->assertTrue(array_key_exists('name', $x), json_encode($x));
     $this->assertTrue(array_key_exists('interests', $x), json_encode($x));
 }
开发者ID:kph11,项目名称:mongo-php-driver,代码行数:23,代码来源:SlowTests.php


示例12: count

 /**
  * Count the results
  *
  * @since v1.0.0
  */
 public function count($foundOnly = FALSE)
 {
     $count = array();
     try {
         $count = $this->_cursor->count($foundOnly);
     } catch (MongoCursorException $exception) {
         show_error($exception->getMessage(), 500);
     } catch (MongoConnectionException $exception) {
         show_error($exception->getMessage(), 500);
     } catch (MongoCursorTimeoutException $exception) {
         show_error($exception->getMessage(), 500);
     }
     return $count;
 }
开发者ID:AnthemiusGuo,项目名称:managerproject,代码行数:19,代码来源:Cimongo_cursor.php


示例13: __construct

 /**
  * 
  * @param \MongoDb $db
  * @param \Mongodloid_Connection $connection
  */
 public function __construct(\MongoDb $db, \Mongodloid_Connection $connection)
 {
     parent::__construct($db, $connection);
     // TODO: refatoring the collections to factory (loose coupling)
     $this->collections = Billrun_Factory::config()->getConfigValue('db.collections', array());
     $timeout = Billrun_Factory::config()->getConfigValue('db.timeout', 3600000);
     // default 60 minutes
     if ($this->compareClientVersion('1.5.3', '<')) {
         Billrun_Factory::log()->log('Set database cursor timeout to: ' . $timeout, Zend_Log::INFO);
         @(MongoCursor::$timeout = $timeout);
     } else {
         // see also bugs:
         // https://jira.mongodb.org/browse/PHP-1099
         // https://jira.mongodb.org/browse/PHP-1080
         $db->setWriteConcern($db->getWriteConcern()['w'], $timeout);
     }
 }
开发者ID:ngchie,项目名称:system,代码行数:22,代码来源:Db.php


示例14: testGlobalTimeout

 /**
  * Test global timeouts and native mappings
  */
 public function testGlobalTimeout()
 {
     // Create collection
     $default_timeout = \MongoCursor::$timeout;
     $collection = $this->getTestCollection();
     // Create a cursor object
     $cursor = $collection->find();
     $native_cursor = $cursor->native;
     // Assert cursor timeouts are updated
     $this->assertEquals($cursor::$timeout, $native_cursor::$timeout);
     // Check that static timeouts are binded
     $default_timeout = \MongoCursor::$timeout;
     $cursor::$timeout = $default_timeout / 2;
     $this->assertEquals(\MongoCursor::$timeout, $cursor::$timeout);
     $this->assertEquals(\MongoMinify\Cursor::$timeout, $cursor::$timeout);
     \MongoCursor::$timeout = 200;
     $this->assertEquals(\MongoCursor::$timeout, \MongoMinify\Cursor::$timeout);
     $this->assertEquals(\MongoMinify\Cursor::$timeout, 200);
     \MongoCursor::$timeout = $default_timeout;
 }
开发者ID:marcqualie,项目名称:mongominify,代码行数:23,代码来源:CursorTest.php


示例15: 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


示例16: sort

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


示例17: getReadPreference

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


示例18: 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


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP MongoDB类代码示例发布时间:2022-05-23
下一篇:
PHP MongoCollection类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap