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


PHP MongoCollection::getIndexInfo方法代码示例

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


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

示例1: _ensureIndex

 /**
  * Ensure index of correct specification and a unique name whether the specification or name already exist or not.
  * Will not create index if $index is a prefix of an existing index
  *
  * @param array $index index to create in same format as \MongoCollection::ensureIndex()
  *
  * @return void
  *
  * @throws \Exception couldnt create index after 5 attempts
  */
 private function _ensureIndex(array $index)
 {
     //if $index is a prefix of any existing index we are good
     foreach ($this->_collection->getIndexInfo() as $existingIndex) {
         $slice = array_slice($existingIndex['key'], 0, count($index), true);
         if ($slice === $index) {
             return;
         }
     }
     for ($i = 0; $i < 5; ++$i) {
         for ($name = uniqid(); strlen($name) > 0; $name = substr($name, 0, -1)) {
             //creating an index with same name and different spec does nothing.
             //creating an index with same spec and different name does nothing.
             //so we use any generated name, and then find the right spec after we have called, and just go with that name.
             try {
                 $this->_collection->ensureIndex($index, array('name' => $name, 'background' => true));
             } catch (\MongoException $e) {
                 //this happens when the name was too long, let continue
             }
             foreach ($this->_collection->getIndexInfo() as $existingIndex) {
                 if ($existingIndex['key'] === $index) {
                     return;
                 }
             }
         }
     }
     throw new \Exception('couldnt create index after 5 attempts');
 }
开发者ID:diffion,项目名称:php-mongo-queue,代码行数:38,代码来源:Queue.php

示例2: testGetIndexInfo

 public function testGetIndexInfo()
 {
     $info = $this->object->getIndexInfo();
     $this->assertEquals(count($info), 0);
     $this->object->ensureIndex(array('foo' => 1));
     $this->object->ensureIndex(array('foo' => -1));
     $this->object->ensureIndex(array('bar' => 1, 'baz' => -1));
     $info = $this->object->getIndexInfo();
     $this->assertEquals(4, count($info), json_encode($info));
     $this->assertEquals($info[1]['key']['foo'], 1);
     $this->assertEquals($info[1]['name'], 'foo_1');
     $this->assertEquals($info[2]['key']['foo'], -1);
     $this->assertEquals($info[2]['name'], 'foo_-1');
     $this->assertEquals($info[3]['key']['bar'], 1);
     $this->assertEquals($info[3]['key']['baz'], -1);
     $this->assertEquals($info[3]['name'], 'bar_1_baz_-1');
 }
开发者ID:salathe,项目名称:mongo-php-driver,代码行数:17,代码来源:MongoCollectionTest.php

示例3: getIndexInfo

 /**
  * Wrapper method for MongoCollection::getIndexInfo().
  *
  * @see http://php.net/manual/en/mongocollection.getindexinfo.php
  * @return array
  */
 public function getIndexInfo()
 {
     return $this->mongoCollection->getIndexInfo();
 }
开发者ID:pmnyaga,项目名称:mongodb,代码行数:10,代码来源:Collection.php

示例4: getIndexInfo

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


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