getCollectionNames() public method

Get all collections from this database
public getCollectionNames ( array $options = [] ) : array
$options array An array of options for listing the collections.
return array Returns the names of the all the collections in the database as an array
示例#1
0
 /**
  * List collections in a DB
  * 
  * @param MongoDB $db DB
  * @return array<MongoCollection>
  */
 static function listCollections(MongoDB $db)
 {
     $server = MServer::currentServer();
     $names = array();
     try {
         $names = $db->getCollectionNames(true);
     } catch (Exception $e) {
     }
     $ret = array();
     foreach ($names as $name) {
         if ($server->shouldHideCollection($name)) {
             continue;
         }
         if (preg_match("/^system\\./", $name)) {
             continue;
         }
         $ret[] = $name;
     }
     sort($ret);
     //system collections
     if (!$server->uiHideSystemCollections()) {
         foreach ($names as $name) {
             if ($server->shouldHideCollection($name)) {
                 continue;
             }
             if (preg_match("/^system\\./", $name)) {
                 $ret[] = $name;
             }
         }
     }
     $collections = array();
     foreach ($ret as $v) {
         if ($v === "") {
             //older MongoDB version (maybe before 1.7) allow empty collection name
             continue;
         }
         $collections[] = $db->selectCollection($v);
     }
     return $collections;
 }
示例#2
0
 public function getTableNames($schema = null, $refresh = false, $use_alias = false)
 {
     if ($refresh || empty($this->tableNames) && null === ($this->tableNames = $this->getFromCache('table_names'))) {
         /** @type TableSchema[] $names */
         $names = [];
         $tables = $this->dbConn->getCollectionNames();
         foreach ($tables as $table) {
             $names[strtolower($table)] = new TableSchema(['name' => $table]);
         }
         // merge db extras
         if (!empty($extrasEntries = $this->getSchemaExtrasForTables($tables, false))) {
             foreach ($extrasEntries as $extras) {
                 if (!empty($extraName = strtolower(strval($extras['table'])))) {
                     if (array_key_exists($extraName, $tables)) {
                         $names[$extraName]->fill($extras);
                     }
                 }
             }
         }
         $this->tableNames = $names;
         $this->addToCache('table_names', $this->tableNames, true);
     }
     return $this->tableNames;
 }
示例#3
0
 /**
  * 获取数据库中的文档列表
  * @param MongoDB $db DB
  * @return array<MongoCollection>
  */
 public function _listCollections(MongoDB $db)
 {
     //获取所有文档列表
     $names = array();
     try {
         //$names = $db->execute('function (){ return db.getCollectionNames(); }');	//生产线不支持js格式mongo指令
         $names = $db->getCollectionNames();
     } catch (Exception $e) {
         echo $e->errorMessage();
         exit;
     }
     //获取非系统文档
     $ret = array();
     $inlay_tabse = Yii::app()->params['inlay_tabse'];
     foreach ($names as $name) {
         //屏蔽掉系统文档和item
         if (preg_match("/^(system\\.|auto|file\\.)/", $name)) {
             continue;
         }
         $ret[$name] = isset($inlay_tabse[$name]) ? $inlay_tabse[$name] : $name;
     }
     //拆分item表
     $dsmap = CardDs::model()->getDBDSMap();
     //获取游戏表对应
     foreach ($dsmap as $dv) {
         foreach ($dv['list'] as $tv) {
             $ret['item_' . $dv['en_name'] . '_' . $tv['en_name']] = '数据表_' . $dv['name'] . '_' . $tv['name'];
         }
     }
     $names = $ret;
     return $names;
 }