MongoDB::listCollections
(PECL mongo >=0.9.0)
MongoDB::listCollections — Gets an array of MongoCollection objects for all collections in this database
Описание
$options
= array()
] )Gets a list of all collections in the database and returns them as an array of MongoCollection objects.
Замечание: This method will use the » listCollections database command when communicating with MongoDB 2.8+. For previous database versions, the method will query the special system.namespaces collection.
Список параметров
-
options
-
An array of options for listing the collections. Currently available options include:
"filter"
Optional query criteria. If provided, this criteria will be used to filter the collections included in the result.
Relevant fields that may be queried include "name" (collection name as a string, without the database name prefix) and "options" (object containing options used to create the collection)..
Замечание: MongoDB 2.6 and earlier versions require the "name" criteria, if specified, to be a string value (i.e. equality match). This is because the driver must prefix the value with the database name in order to query the system.namespaces collection. Later versions of MongoDB do not have this limitation, as the driver will use the listCollections command.
"includeSystemCollections"
Boolean, defaults to
FALSE
. Determines whether system collections should be included in the result.
The following option may be used with MongoDB 2.8+:
"maxTimeMS"
Указывает суммарный лимит времени в миллисекундах на обработку операции (не включая время простоя). Если операция не завершилась за это время, то бросается MongoExecutionTimeoutException.
Возвращаемые значения
Returns an array of MongoCollection objects.
Ошибки
For MongoDB 2.6 and earlier, MongoException will be thrown if a non-string value was specified for the "filter" option's "name" criteria.
Список изменений
Версия | Описание |
---|---|
1.6.0 | Changed first parameter to be an array of options. Pre-1.6.0, the first parameter was a boolean indicating the "includeSystemCollections" option. |
1.3.0 |
Added the includeSystemCollections parameter.
|
Примеры
Пример #1 MongoDB::listCollections() example
The following example demonstrates running count on each collection in a database.
<?php
$m = new MongoClient();
$db = $m->selectDB("demo");
$collections = $db->listCollections();
foreach ($collections as $collection) {
echo "amount of documents in $collection: ";
echo $collection->count(), "\n";
}
?>
Результатом выполнения данного примера будет что-то подобное:
... amount of documents in demo.pubs: 4 amount of documents in demo.elephpants: 3 amount of documents in demo.cities: 22840 ...
Смотрите также
- MongoDB::getCollectionNames() - Gets an array of names for all collections in this database
- MongoDB::getCollectionInfo() - Returns information about collections in this database
- 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
Коментарии
For an alternative to the shell command 'show dbs', refer to my note for the listDBs() method of Mongoclient(), which reproduces some simple PHP code that will yield the names of all database present.