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


PHP Mongo::ensureIndex方法代码示例

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


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

示例1: ensureIndex

 public function ensureIndex($keys, $options = array())
 {
     try {
         $options = array_merge($options, array('safe' => TRUE));
         return parent::ensureIndex($keys, $options);
     } catch (MongoCursorException $e) {
         show_error("MongoDB ensureIndex failed: {$e->getMessage()}", 500);
     }
 }
开发者ID:navruzm,项目名称:navruz.net,代码行数:9,代码来源:Mongo_db.php

示例2: testGetIndexInfo

 public function testGetIndexInfo()
 {
     $info = $this->object->getIndexInfo();
     $this->assertEquals(count($info), 0);
     $this->object->ensureIndex((object) array('foo' => 1));
     $this->object->ensureIndex((object) array('foo' => -1));
     $this->object->ensureIndex((object) 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:redmeadowman,项目名称:mongo-php-driver,代码行数:17,代码来源:MongoObjectsTest.php

示例3: __initMongoSession

 private function __initMongoSession()
 {
     // generate server connection strings
     $connections = array();
     if (!empty($this->_settings['servers'])) {
         foreach ($this->_settings['servers'] as $server) {
             $str = '';
             if (!empty($server['username']) && !empty($server['password'])) {
                 $str .= $server['username'] . ':' . $server['password'] . '@';
             }
             $str .= !empty($server['host']) ? $server['host'] : Mongo::DEFAULT_HOST;
             $str .= ':' . (!empty($server['port']) ? (int) $server['port'] : Mongo::DEFAULT_PORT);
             array_push($connections, $str);
         }
     } else {
         // use default connection settings
         array_push($connections, Mongo::DEFAULT_HOST . ':' . Mongo::DEFAULT_PORT);
     }
     // add immediate connection
     $opts = array('connect' => true);
     // support persistent connections
     if ($this->_settings['persistent'] && !empty($this->_settings['persistentId'])) {
         $opts['persist'] = $this->_settings['persistentId'];
     }
     // support replica sets
     if ($this->_settings['replicaSet']) {
         $opts['replicaSet'] = true;
     }
     // load mongo server connection
     try {
         $this->_connection = new Mongo('mongodb://' . implode(',', $connections), $opts);
     } catch (Exception $e) {
         throw new Exception('Can\'t connect to the MongoDB server.');
     }
     // load the db
     try {
         $mongo = $this->_connection->selectDB($this->_settings['database']);
     } catch (InvalidArgumentException $e) {
         throw new Exception('The MongoDB database specified in the config does not exist.');
     }
     // load collection
     try {
         $this->_mongo = $mongo->selectCollection($this->_settings['collection']);
     } catch (Exception $e) {
         throw new Exception('The MongoDB collection specified in the config does not exist.');
     }
     // proper indexing on the expiration
     $this->_mongo->ensureIndex(array('expiry' => 1), array('name' => 'expiry', 'unique' => true, 'dropDups' => true, 'safe' => true));
     // proper indexing of session id and lock
     $this->_mongo->ensureIndex(array('session_id' => 1, 'lock' => 1), array('name' => 'session_id', 'unique' => true, 'dropDups' => true, 'safe' => true));
 }
开发者ID:radig,项目名称:CakeMongoSession,代码行数:51,代码来源:cake_mongo_session.php


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