當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Mongo::selectCollection方法代碼示例

本文整理匯總了PHP中Mongo::selectCollection方法的典型用法代碼示例。如果您正苦於以下問題:PHP Mongo::selectCollection方法的具體用法?PHP Mongo::selectCollection怎麽用?PHP Mongo::selectCollection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mongo的用法示例。


在下文中一共展示了Mongo::selectCollection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: connect

 /**
  * {@inheritdoc}
  */
 public function connect(array $config)
 {
     $requiredParams = array('hostname', 'db', 'collection');
     foreach ($requiredParams as $param) {
         if (!isset($config[$param])) {
             throw new SetupException('Missing config attribute "' . $param . '"');
         }
     }
     $port = isset($config['port']) ? (int) $config['port'] : 27017;
     $mongo = new \Mongo('mongodb://' . $config['hostname'] . ':' . $port);
     $this->adapter = $mongo->selectDB($config['db']);
     $this->collection = $this->adapter->selectCollection($config['collection']);
     return $this;
 }
開發者ID:voldern,項目名稱:phactory,代碼行數:17,代碼來源:MongoDB.php

示例2:

 /**
  * 構造查詢
  *
  * @param Mongo $mongo MongoDB連接
  * @param string $db 數據庫
  * @param string $collection 集合
  */
 function __construct(Mongo $mongo, $db, $collection)
 {
     $this->_dbName = $db;
     $this->_collectionName = $collection;
     $this->_db = $mongo->selectDB($this->_dbName);
     $this->_collection = $mongo->selectCollection($this->_dbName, $this->_collectionName);
 }
開發者ID:jango2015,項目名稱:nette-mongodb-sandbox,代碼行數:14,代碼來源:RQuery.php

示例3: testBasic

 public function testBasic()
 {
     $r1 = new MongoRegex("//");
     $this->assertEquals($r1->regex, "");
     $this->assertEquals($r1->flags, "");
     $r2 = new MongoRegex("/foo/bar");
     $this->assertEquals($r2->regex, "foo");
     $this->assertEquals($r2->flags, "bar");
     $r3 = new MongoRegex($r2);
     $this->assertEquals($r3->regex, "foo");
     $this->assertEquals($r3->flags, "bar");
     $stupid_str = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
     $rstupid = new MongoRegex("/{$stupid_str}/flagflagflagflagflag");
     $this->assertEquals($rstupid->regex, $stupid_str);
     $this->assertEquals($rstupid->flags, "flagflagflagflagflag");
     $m = new Mongo();
     $c = $m->selectCollection('phpunit', 'regex');
     $c->drop();
     $c->insert(array('x' => 0, 'r1' => $r1));
     $c->insert(array('x' => 1, 'r2' => $r2));
     $c->insert(array('x' => 2, 'stupid' => $rstupid));
     $obj = $c->findOne(array('x' => 0));
     $this->assertEquals($obj['r1']->regex, "");
     $this->assertEquals($obj['r1']->flags, "");
     $obj = $c->findOne(array('x' => 1));
     $this->assertEquals($obj['r2']->regex, "foo");
     $this->assertEquals($obj['r2']->flags, "bar");
     $obj = $c->findOne(array('x' => 2));
     $this->assertEquals($obj['stupid']->regex, $stupid_str);
     $this->assertEquals($obj['stupid']->flags, "flagflagflagflagflag");
 }
開發者ID:rjonker,項目名稱:mongo-php-driver,代碼行數:31,代碼來源:MongoRegexTest.php

示例4: setUp

 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $m = new Mongo();
     $this->object = $m->selectCollection('phpunit', 'c');
     $this->object->drop();
     //        $this->object->start = memory_get_usage(true);
 }
開發者ID:redmeadowman,項目名稱:mongo-php-driver,代碼行數:13,代碼來源:MongoCursorTest.php

示例5: getCollection

 /**
  * Return a "MongoCollection" instance.
  *
  * @return \MongoCollection
  */
 private function getCollection()
 {
     if (null === $this->collection) {
         $this->collection = $this->mongo->selectCollection($this->options['database'], $this->options['collection']);
     }
     return $this->collection;
 }
開發者ID:ccq18,項目名稱:EduSoho,代碼行數:12,代碼來源:MongoDbSessionHandler.php

示例6: init

 /**
  * Init 初始化
  * @param string $db
  * @param string $collection
  */
 public static function init($db = '', $collection = '')
 {
     if (!self::$_mongoDB) {
         $config = self::$_config;
         $conStr = "mongodb://";
         if ($config['user'] && $config['password']) {
             $conStr .= "{$config['user']}:{$config['password']}@";
         }
         $conStr .= "{$config['host']}:{$config['port']}";
         $_mongoDB = new Mongo($conStr, array("connect" => false));
         if ($db && $collection) {
             self::$_mongoDB = $_mongoDB->selectCollection($db, $collection);
         } else {
             self::$_mongoDB = $_mongoDB->selectCollection(static::$_db, static::$_collection);
         }
     }
 }
開發者ID:Birjemin,項目名稱:Cmd_library,代碼行數:22,代碼來源:mongodbTool.php

示例7: getMongo

 /**
  * Internal convenience method that returns the instance of the MongoDB Collection
  *
  * @return \MongoCollection
  */
 protected function getMongo()
 {
     if ($this->mongo === null) {
         $mongo = new \Mongo($this->dsn);
         list($database, $collection, ) = explode('/', substr(parse_url($this->dsn, PHP_URL_PATH), 1));
         $this->mongo = $mongo->selectCollection($database, $collection);
     }
     return $this->mongo;
 }
開發者ID:nizam-uddin,項目名稱:symfony,代碼行數:14,代碼來源:MongoDbProfilerStorage.php

示例8: setup

 function setup()
 {
     if (PHP_INT_SIZE != 4) {
         $this->markTestSkipped("Only for 32 bit platforms");
     }
     ini_set('mongo.native_long', 0);
     ini_set('mongo.long_as_object', 0);
     $m = new Mongo();
     $this->object = $m->selectCollection("phpunit", "ints");
     $this->object->drop();
 }
開發者ID:rjonker,項目名稱:mongo-php-driver,代碼行數:11,代碼來源:MongoInt32Test.php

示例9: testDropDB

 public function testDropDB()
 {
     $this->object->connect();
     $c = $this->object->selectCollection("temp", "foo");
     $c->insert(array('x' => 1));
     $this->object->dropDB("temp");
     $this->assertEquals($c->findOne(), NULL);
     $db = $this->object->selectDB("temp");
     $c->insert(array('x' => 1));
     $this->object->dropDB($db);
     $this->assertEquals($c->findOne(), NULL);
 }
開發者ID:salathe,項目名稱:mongo-php-driver,代碼行數:12,代碼來源:MongoTest.php

示例10: insertarTweetInfo

 function insertarTweetInfo($id_tweet, $tweet, $rts, $favs, $fecha_creacion, $usuario, $url_imagen, $followers, $following, $num_tweets)
 {
     //creamos la conexion con la BD
     $mongo = new Mongo();
     $db = $mongo->selectDB("TwettsDB");
     $c_twettsMovilidad = $mongo->selectCollection("TwettsDB", "twettsMovilidad");
     $nuevoTweet = array("ID" => $id_tweet, "TWETT" => $tweet, "RETWETTS" => $rts, "FAVORITOS" => $favs, "FECHA_CREACION" => $fecha_creacion, "USUARIO" => $usuario, "URL_IMAGEN" => $url_imagen, "N_MIS_SEGUIDORES" => $followers, "N_SEGUIDORES" => $following, "N_TWETTS_ENVIADOS" => $num_tweets);
     $c_twettsMovilidad->insert($nuevoTweet);
     $twettsMovilidad = $c_twettsMovilidad->find();
     foreach ($twettsMovilidad as $twett) {
         print_r($twett);
     }
 }
開發者ID:alejo7,項目名稱:ProyectoBimestral2,代碼行數:13,代碼來源:bajartwetts.php

示例11: testGetDBRef

 public function testGetDBRef()
 {
     $c = $this->object->selectCollection('foo');
     $c->drop();
     for ($i = 0; $i < 50; $i++) {
         $c->insert((object) array('x' => rand()), array("safe" => true));
     }
     $obj = $c->findOne();
     $ref = $this->object->createDBRef('foo', $obj);
     $obj2 = $this->object->getDBRef($ref);
     $this->assertNotNull($obj2);
     $this->assertEquals($obj['x'], $obj2['x']);
 }
開發者ID:redmeadowman,項目名稱:mongo-php-driver,代碼行數:13,代碼來源:MongoObjDBTest.php

示例12: testConstruct

 public function testConstruct()
 {
     $m = new Mongo("localhost:27017,localhost:27018", false);
     $m->pairConnect();
     $c = $m->selectCollection("phpunit", "test");
     $c->insert(array("foo", "bar"));
     $left = new Mongo("localhost:27017");
     $left->selectCollection("foo", "bar")->insert(array('x' => 1));
     $lerr = $left->lastError();
     $right = new Mongo("localhost:27018");
     $right->selectCollection("foo", "bar")->insert(array('x' => 1));
     $rerr = $right->lastError();
 }
開發者ID:kph11,項目名稱:mongo-php-driver,代碼行數:13,代碼來源:MongoPairTest.php

示例13: initialize

 /**
  * Initializes this logger.
  *
  * @throws sfInitializationException
  *
  * @param  sfEventDispatcher $dispatcher  A sfEventDispatcher instance
  * @param  array             $options     An array of options.
  *
  * @return bool
  */
 public function initialize(sfEventDispatcher $dispatcher, $options = array())
 {
     if (!class_exists('Mongo')) {
         throw new sfInitializationException('The MongoDB extension is not installed or enabled.');
     }
     foreach ($this->getRequiredOptions() as $eachOption) {
         if (!isset($options[$eachOption])) {
             throw new sfInitializationException(sprintf('The required option "%s" is missing.', $eachOption));
         }
     }
     $this->options = array_merge($this->getDefaultOptions(), $options);
     if ($this->options['username'] and $this->options['password']) {
         $this->handler = new Mongo(sprintf('mongodb://%s:%s@%s:%d/%s', $this->options['username'], $this->options['password'], $this->options['host'], $this->options['port'], $this->options['database']));
     } else {
         $this->handler = new Mongo(sprintf('mongodb://%s:%d', $this->options['host'], $this->options['port']));
     }
     if (!empty($this->options['create'])) {
         $this->handler->selectDB($this->options['database'])->createCollection($this->options['collection'], $this->options['create']['capped'], $this->options['create']['size'], $this->options['create']['max']);
     }
     $this->collection = $this->handler->selectCollection($this->options['database'], $this->options['collection']);
     return parent::initialize($dispatcher, $this->options);
 }
開發者ID:havvg,項目名稱:sfMongoDBLoggerPlugin,代碼行數:32,代碼來源:sfMongoDBLogger.class.php

示例14: testMethods

 public function testMethods()
 {
     $m = new Mongo();
     $c = $m->selectCollection('phpunit', 'objs4');
     $c->drop();
     $f = new Foo();
     $c->insert($f);
     $f->x = 3;
     $c->save($f);
     $f->y = 7;
     $c->update(array('_id' => $f->_id), $f);
     $c->remove($f);
 }
開發者ID:redmeadowman,項目名稱:mongo-php-driver,代碼行數:13,代碼來源:MongoObjectsTest.php

示例15: getMongo

 /**
  * Internal convenience method that returns the instance of the MongoDB Collection
  *
  * @return \MongoCollection
  */
 protected function getMongo()
 {
     if ($this->mongo === null) {
         if (preg_match('#^(mongodb://.*)/(.*)/(.*)$#', $this->dsn, $matches)) {
             $mongo = new \Mongo($matches[1] . (!empty($matches[2]) ? '/' . $matches[2] : ''));
             $database = $matches[2];
             $collection = $matches[3];
             $this->mongo = $mongo->selectCollection($database, $collection);
         } else {
             throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use MongoDB with an invalid dsn "%s". The expected format is "mongodb://user:pass@location/database/collection"', $this->dsn));
         }
     }
     return $this->mongo;
 }
開發者ID:netvlies,項目名稱:symfony,代碼行數:19,代碼來源:MongoDbProfilerStorage.php


注:本文中的Mongo::selectCollection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。