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


PHP MongoDB::createCollection方法代码示例

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


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

示例1: setUp

 public function setUp()
 {
     if (is_null($this->database)) {
         $client = new \MongoClient();
         $this->database = $client->selectDB('DbMockLibraryTest');
     }
     $this->database->dropCollection('testCollection');
     $this->database->createCollection('testCollection');
     Mongo::initMongo(['testCollection' => [1 => ['foo' => 0, '_id' => 0]]], 'DbMockLibraryTest', []);
 }
开发者ID:komita1981,项目名称:DbMockLibrary,代码行数:10,代码来源:InsertTest.php

示例2: __construct

 /**
  * Constructor. Sets the Mongo DB adapter.
  *
  * @param \MongoClient $Mongo     A \MongoClient instance.
  * @param array        $options   Array of options.
  */
 public function __construct(\MongoClient $Mongo, array $options = null)
 {
     // default options
     $this->options['db_name'] = 'apix';
     $this->options['collection_name'] = 'cache';
     $this->options['object_serializer'] = 'php';
     // null, php, json, igBinary.
     // Set the adapter and merge the user+default options
     parent::__construct($Mongo, $options);
     $this->db = $this->adapter->selectDB($this->options['db_name']);
     $this->collection = $this->db->createCollection($this->options['collection_name'], false);
     $this->collection->ensureIndex(array('key' => 1), array('unique' => true, 'dropDups' => true));
     // Using MongoDB TTL collections (MongoDB 2.2+)
     $this->collection->ensureIndex(array('expire' => 1), array('expireAfterSeconds' => 1));
     $this->setSerializer($this->options['object_serializer']);
 }
开发者ID:MacFJA,项目名称:apix-cache,代码行数:22,代码来源:Mongo.php

示例3: createCollection

 /**
  * createCollection.
  */
 public function createCollection($name, $capped = null, $capped_size = null, $max_elements = null)
 {
     $this->time->start();
     $return = parent::createCollection($name, $capped, $size, $max);
     $time = $this->time->stop();
     $this->log(array('type' => 'createCollection', 'name' => $name, 'options' => $options));
     return $return;
 }
开发者ID:mongator,项目名称:mongator,代码行数:11,代码来源:LoggableMongoDB.php

示例4: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $categoryCol = $this->mongo->createCollection(CategoryMeta::SHORT_NAME);
     var_dump($categoryCol->ensureIndex([CategoryMeta::ESHOP_ID => 1, CategoryMeta::HASH => 1], ["unique" => true]));
     $productCol = $this->mongo->createCollection(ProductMeta::SHORT_NAME);
     var_dump($productCol->ensureIndex([ProductMeta::ESHOP_ID => 1, ProductMeta::ITEM_GROUP_ID => 1, ProductMeta::ITEM_ID => 1], ["unique" => true]));
     var_dump($productCol->ensureIndex(["_id" => 1, ProductMeta::V => 1], ["unique" => true]));
     $eshopCol = $this->mongo->createCollection(EshopMeta::SHORT_NAME);
     var_dump($eshopCol->ensureIndex([EshopMeta::SLUG => 1]), ["unique" => true]);
     $f = fopen($input->getArgument("csv"), "r");
     while (list($slug, $url, $feedUrl) = fgetcsv($f)) {
         $eshop = new Eshop();
         $eshop->setName($slug)->setSlug($slug)->setUrl($url)->setFeeds([(new Feed())->setId(new \MongoId())->setUrl($feedUrl)]);
         $eshopDoc = $this->eshopRepository->findAndModify([EshopMeta::SLUG => $slug], EshopMeta::toArray($eshop), ["_id"], ["upsert" => true, "new" => true]);
         var_dump($eshopDoc);
     }
 }
开发者ID:skrz,项目名称:cc15-mongo-es-redis-rabbitmq,代码行数:17,代码来源:MongoCommand.php

示例5: createCollection

 /**
  * createCollection.
  */
 public function createCollection($name, $capped = false, $size = 0, $max = 0)
 {
     $this->time->start();
     $return = parent::createCollection($name, $capped, $size, $max);
     $time = $this->time->stop();
     $this->log(array('type' => 'createCollection', 'name' => $name, 'capped' => $capped, 'size' => $size, 'max' => $max));
     return $return;
 }
开发者ID:robo47,项目名称:mandango,代码行数:11,代码来源:LoggableMongoDB.php

示例6: doCreateCollection

 /**
  * Creates a collection.
  *
  * @see Database::createCollection()
  * @param string $name
  * @param array $options
  * @return Collection
  */
 protected function doCreateCollection($name, array $options)
 {
     if (version_compare(phpversion('mongo'), '1.4.0', '>=')) {
         $this->mongoDB->createCollection($name, $options);
     } else {
         $this->mongoDB->createCollection($name, $options['capped'], $options['size'], $options['max']);
     }
     return $this->doSelectCollection($name);
 }
开发者ID:Wizkunde,项目名称:mongodb,代码行数:17,代码来源:Database.php

示例7: _createCollection

 /**
  * @param string $collectionname
  * @return boolean Whether the operation was successful
  */
 protected function _createCollection($collectionname)
 {
     try {
         $this->dbcon->createCollection($collectionname);
         $this->numQueries++;
         return true;
     } catch (Exception $e) {
         $this->errors[] = $e->__toString() . ', caught in ' . __CLASS__ . '::' . __METHOD__ . '()';
     }
     return false;
 }
开发者ID:vallejos,项目名称:samples,代码行数:15,代码来源:TeraWurflDatabase_MongoDB.php

示例8: testDBCommand

 public function testDBCommand()
 {
     $x = $this->object->command(array());
     $this->assertEquals(0, strpos($x['errmsg'], "no such cmd"), json_encode($x));
     $this->assertEquals((bool) $x['ok'], false);
     $created = $this->object->createCollection("system.profile", true, 5000);
     $this->object->command(array('profile' => 0));
     $x = $this->object->command(array('profile' => 1));
     $this->assertEquals($x['was'], 0, json_encode($x));
     $this->assertEquals((bool) $x['ok'], true, json_encode($x));
 }
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:11,代码来源:MongoDBTest.php

示例9: createCollection

 /**
  * Creates a collection
  * @param string $collection
  */
 public function createCollection($collection)
 {
     if ($collection) {
         $this->mongo->createCollection($collection);
     }
 }
开发者ID:Jason3S,项目名称:wikimarkup-wiktionary-original,代码行数:10,代码来源:moadmin.php

示例10: doCreateCollection

 /**
  * Creates a collection.
  *
  * @see Database::createCollection()
  * @param string $name
  * @param array $options
  * @return Collection
  */
 protected function doCreateCollection($name, array $options)
 {
     $this->mongoDB->createCollection($name, $options);
     return $this->doSelectCollection($name);
 }
开发者ID:alcaeus,项目名称:mongodb,代码行数:13,代码来源:Database.php

示例11: createCollection

 public function createCollection($name, $options = array())
 {
     parent::createCollection($name, $options);
     return $this->selectCollection($name);
 }
开发者ID:lisong,项目名称:incubator,代码行数:5,代码来源:Db.php

示例12: createCollection

 /**
  * Create collection
  *
  * @param MongoDB $db MongoDB
  * @param string $name Collection name
  * @param array $options Options, capped, size, max
  */
 public static function createCollection(MongoDB $db, $name, array $options)
 {
     if (RMongo::compareVersion("1.4.0") >= 0) {
         $db->createCollection($name, $options);
     } else {
         $db->createCollection($name, isset($options["capped"]) ? $options["capped"] : false, isset($options["size"]) ? $options["size"] : 0, isset($options["max"]) ? $options["max"] : 0);
     }
 }
开发者ID:boosen,项目名称:rockmongo,代码行数:15,代码来源:MCollection.php

示例13: forOneStringCollect

function forOneStringCollect(MongoDB $db)
{
    $streets = $db->streets;
    $cities = $db->cities;
    $districts = $db->district;
    $regions = $db->regions;
    $buildings = $db->buildings;
    /*
     * Массив всех элементов будущей таблицы
     */
    //удаляем-создаём таблицу
    $db->complex->drop();
    $db->createCollection('complex');
    // Здания
    $allBuildings = $buildings->find(array(), array('NormalizedName' => 1, 'Name' => 1, 'Id' => 1, 'ZipCode' => 1, 'TypeShort' => 1, 'Type' => 1, 'Okato' => 1, 'CodeRegion' => 1, 'CodeDistrict' => 1, 'CodeCity' => 1, 'CodeStreet' => 1, 'CodeBuilding' => 1));
    echo 'buildings';
    $i = 0;
    foreach ($allBuildings as $arBuilding) {
        if ($i++ % 10000 == 0) {
            echo $i . '; ';
        }
        //здания с одним id
        $building = $arBuilding;
        $building['NormalizedName'] = $arBuilding['NormalizedName'];
        $building['Sort'] = 50;
        $building['BuildingId'] = $arBuilding['Id'];
        //        $building['Address'] = array();
        //        $building['Address'] = array_merge($building['Address'], $arBuilding['NormalizedName']);
        //$building['FullName'] .= $arBuilding['NormalizedName']; //без имени дома
        $building['FullName'] = null;
        $building['StreetId'] = null;
        $building['CityId'] = null;
        $building['DistrictId'] = null;
        $building['RegionId'] = null;
        $building['NormalizedBuildingName'] = $arBuilding['NormalizedName'];
        $building['NormalizedStreetName'] = null;
        $building['NormalizedCityName'] = null;
        $building['NormalizedDistrictName'] = null;
        $building['NormalizedRegionName'] = null;
        $building['ContentType'] = 'building';
        //ищем айдишники её городов и заполняем поле address т.п.
        $street = $streets->findOne(array('CodeStreet' => $building['CodeStreet'], 'CodeCity' => $building['CodeCity'], 'CodeDistrict' => $building['CodeDistrict'], 'CodeRegion' => $building['CodeRegion'], 'Bad' => false), array('Name' => 1, 'NormalizedName' => 1, 'Id' => 1, 'TypeShort' => 1, 'Type' => 1));
        if ($street) {
            $building['StreetId'] = $street['Id'];
            //            $building['Address'] = array_merge($building['Address'], $street['NormalizedName']);
            $building['NormalizedStreetName'] = $street['NormalizedName'];
        }
        $city = $cities->findOne(array('CodeCity' => $building['CodeCity'], 'CodeDistrict' => $building['CodeDistrict'], 'CodeRegion' => $building['CodeRegion'], 'Bad' => false), array('Name' => 1, 'NormalizedName' => 1, 'Id' => 1, 'TypeShort' => 1, 'Type' => 1));
        if ($city) {
            $building['CityId'] = $city['Id'];
            $building['NormalizedCityName'] = $city['NormalizedName'];
        }
        $cityOwner = $cities->findOne(array('Id' => getCityOwnerId($building['BuildingId']), 'Bad' => false), array('Name' => 1, 'NormalizedName' => 1, 'Id' => 1, 'TypeShort' => 1, 'Type' => 1));
        if ($cityOwner) {
            $building['CityOwnerId'] = $cityOwner['Id'];
            $building['NormalizedCityOwnerName'] = $cityOwner['NormalizedName'];
        }
        $district = $districts->findOne(array('CodeDistrict' => $building['CodeDistrict'], 'CodeRegion' => $building['CodeRegion'], 'Bad' => false), array('Name' => 1, 'NormalizedName' => 1, 'Id' => 1, 'TypeShort' => 1, 'Type' => 1));
        if ($district) {
            $building['DistrictId'] = $district['Id'];
            //            $building['Address'] = array_merge($building['Address'], $district['NormalizedName']);
            $building['NormalizedDistrictName'] = $district['NormalizedName'];
        }
        $region = $regions->findOne(array('CodeRegion' => $building['CodeRegion'], 'Bad' => false), array('Name' => 1, 'NormalizedName' => 1, 'Id' => 1, 'TypeShort' => 1, 'Type' => 1));
        if ($region) {
            $building['RegionId'] = $region['Id'];
            //            $building['Address'] = array_merge($building['Address'], $region['NormalizedName']);
            $building['NormalizedRegionName'] = $region['NormalizedName'];
        }
        //собираем все тайпы
        //typesCollect($building, $region, $district, $city, $street, $building);
        //и имя
        constructFullName($building, $region, $district, $city, $street, $cityOwner);
        unset($building['_id']);
        //избегаем ненужных конфликтов
        $db->complex->insert($building);
    }
    // Улицы
    $allStreets = $streets->find(array('Bad' => false), array('NormalizedName' => 1, 'Name' => 1, 'Id' => 1, 'ZipCode' => 1, 'TypeShort' => 1, 'Type' => 1, 'Okato' => 1, 'CodeRegion' => 1, 'CodeDistrict' => 1, 'CodeCity' => 1, 'CodeStreet' => 1));
    echo 'streets';
    $i = 0;
    foreach ($allStreets as $arStreet) {
        if ($i++ % 10000 == 0) {
            echo $i . '; ';
        }
        //сама улица
        $street = $arStreet;
        $street['Sort'] = 40;
        $street['StreetId'] = $arStreet['Id'];
        //        $street['Address'] = array();
        //        $street['Address'] = array_merge($street['Address'], $arStreet['NormalizedName']);
        $street['FullName'] = null;
        $street['CityId'] = null;
        $street['DistrictId'] = null;
        $street['RegionId'] = null;
        $street['NormalizedStreetName'] = $arStreet['NormalizedName'];
        $street['NormalizedCityName'] = null;
        $street['NormalizedDistrictName'] = null;
        $street['NormalizedRegionName'] = null;
        $street['ContentType'] = 'street';
//.........这里部分代码省略.........
开发者ID:olegabr,项目名称:kladrapi,代码行数:101,代码来源:address_collect.php

示例14: doNewCollection

 /** create new collection **/
 public function doNewCollection()
 {
     $this->db = xn("db");
     $this->name = x("name");
     $this->isCapped = xi("is_capped");
     $this->size = xi("size");
     $this->max = xi("max");
     if ($this->isPost()) {
         $db = new MongoDB($this->_mongo, $this->db);
         $db->createCollection($this->name, $this->isCapped, $this->size, $this->max);
         $this->message = "New collection is created.";
         //add index
         if (!$this->isCapped) {
             $db->selectCollection($this->name)->ensureIndex(array("_id" => 1));
         }
     }
     $this->display();
 }
开发者ID:jango2015,项目名称:nette-mongodb-sandbox,代码行数:19,代码来源:db.php

示例15: _call

 protected function _call($command, array $arguments = array(), array $values = NULL)
 {
     $this->_connected or $this->connect();
     extract($arguments);
     $_bm_name = isset($collection_name) ? $collection_name . '.' . $command : $command;
     if (isset($collection_name)) {
         $c = $this->_db->selectCollection($collection_name);
     }
     switch ($command) {
         case 'ensure_index':
             $r = $c->ensureIndex($keys, $options);
             break;
         case 'create_collection':
             $r = $this->_db->createCollection($name, $capped, $size, $max);
             break;
         case 'drop_collection':
             $r = $this->_db->dropCollection($name);
             break;
         case 'command':
             $r = $this->_db->command($values);
             break;
         case 'execute':
             $r = $this->_db->execute($code, $args);
             break;
         case 'batch_insert':
             $r = $c->batchInsert($values);
             break;
         case 'count':
             $r = $c->count($query);
             break;
         case 'find_one':
             $r = $c->findOne($query, $fields);
             break;
         case 'find':
             $r = $c->find($query, $fields);
             break;
         case 'group':
             $r = $c->group($keys, $initial, $reduce, $condition);
             break;
         case 'update':
             $r = $c->update($criteria, $values, $options);
             break;
         case 'insert':
             $r = $c->insert($values, $options);
             break;
         case 'remove':
             $r = $c->remove($criteria, $options);
             break;
         case 'save':
             $r = $c->save($values, $options);
             break;
         case 'get_file':
             $r = $this->gridFS()->findOne($criteria);
             break;
         case 'get_files':
             $r = $this->gridFS()->find($query, $fields);
             break;
         case 'set_file_bytes':
             $r = $this->gridFS()->storeBytes($bytes, $extra, $options);
             break;
         case 'set_file':
             $r = $this->gridFS()->storeFile($filename, $extra, $options);
             break;
         case 'remove_file':
             $r = $this->gridFS()->remove($criteria, $options);
             break;
     }
     if (isset($_bm)) {
         Profiler::stop($_bm);
     }
     return $r;
 }
开发者ID:execrot,项目名称:mongostar,代码行数:72,代码来源:Connection.php


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