MongoDB::getCollectionNames

(PECL mongo >=1.3.0)

MongoDB::getCollectionNamesGets an array of names for all collections in this database

Описание

public array MongoDB::getCollectionNames ([ array $options = array() ] )

Gets a list of all collections in the database and returns their names as an array of strings.

Замечание: 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 the collection names as an array of strings.

Ошибки

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 MongoDB::getCollectionNames() example

<?php
$m 
= new MongoClient();
$db $m->selectDB("demo");
$collections $db->getCollectionNames();

foreach (
$collections as $collectionName) {
    echo 
"Found collection: "$collectionName"\n";
}
?>

Результатом выполнения данного примера будет что-то подобное:

...
Found collection: img
Found collection: beer
Found collection: collation
...

Смотрите также

Коментарии

Автор:
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.
2014-05-31 16:33:11
http://php5.kiev.ua/manual/ru/mongodb.getcollectionnames.html

    Поддержать сайт на родительском проекте КГБ