MongoDB::getCollectionNames
(PECL mongo >=1.3.0)
MongoDB::getCollectionNames — Get all collections from this database
Описание
public array MongoDB::getCollectionNames
([ bool
$includeSystemCollections
= false
] )Returns an array of all the collection names for the given database.
Список параметров
-
includeSystemCollections
-
Include system collections.
Возвращаемые значения
Returns the names of the all the collections in the database as an array.
Примеры
Пример #1 MongoDB::getCollectionNames() example
<?php
$m = new Mongo;
$collections = $m->selectDB("demo")->getCollectionNames();
var_dump($collections);
?>
Результатом выполнения данного примера будет что-то подобное:
array(2) { [0]=> string(9) "addresses" [1]=> string(5) "users" }
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- MongoDB
- Базовые классы
- Функция MongoDB::authenticate() - Log in to this database
- Функция MongoDB::command() - Execute a database command
- Функция MongoDB::__construct() - Creates a new database
- Функция MongoDB::createCollection() - Creates a collection
- Функция MongoDB::createDBRef() - Creates a database reference
- Функция MongoDB::drop() - Drops this database
- Функция MongoDB::dropCollection() - Drops a collection [deprecated]
- Функция MongoDB::execute() - Runs JavaScript code on the database server.
- Функция MongoDB::forceError() - Creates a database error
- Функция MongoDB::__get() - Gets a collection
- MongoDB::getCollectionInfo
- Функция MongoDB::getCollectionNames() - Get all collections from this database
- Функция MongoDB::getDBRef() - Fetches the document pointed to by a database reference
- Функция MongoDB::getGridFS() - Fetches toolkit for dealing with files stored in this database
- Функция MongoDB::getProfilingLevel() - Gets this database's profiling level
- Функция MongoDB::getReadPreference() - Get the read preference for this database
- Функция MongoDB::getSlaveOkay() - Get slaveOkay setting for this database
- Функция MongoDB::getWriteConcern() - Get the write concern for this database
- Функция MongoDB::lastError() - Check if there was an error on the most recent db operation performed
- Функция MongoDB::listCollections() - Gets an array of all MongoCollections for this database
- Функция MongoDB::prevError() - Checks for the last error thrown during a database operation
- Функция MongoDB::repair() - Repairs and compacts this database
- Функция MongoDB::resetError() - Clears any flagged errors on the database
- Функция MongoDB::selectCollection() - Gets a collection
- Функция MongoDB::setProfilingLevel() - Sets this database's profiling level
- Функция MongoDB::setReadPreference() - Set the read preference for this database
- Функция MongoDB::setSlaveOkay() - Change slaveOkay setting for this database
- Функция MongoDB::setWriteConcern() - Set the write concern for this database
- Функция MongoDB::__toString() - The name of this database
Коментарии
A small change to the earlier example will result in a more user-friendly output that will be easier on the eye:
<?php
$dbname = 'members'; // Previously created database
$conn = new MongoClient("localhost");
$list = $conn->selectDB($dbname)->getCollectionNames();
foreach ($list as $coltion) {
$colName = $coltion;
echo '<p>Collection name is: <em>';
echo $colName;
echo '.</em></p>';
}
?>
This will produce an output similar to the following;
Collection name is: addresses.