Returns information about collections in this database

(PECL mongo >=1.6.0)

MongoDB::getCollectionInfoReturns information about collections in this database


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

Gets a list of all collections in the database and returns them as an array of documents, which contain their names and options.

Замечание: 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.

Список параметров


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.

Возвращаемые значения

This function returns an array where each element is an array describing a collection. Elements will contain a name key denoting the name of the collection, and optionally contain an options key denoting an array of objects used to create the collection. For example, capped collections will include capped and size options.


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

= new MongoClient();
$db $m->selectDB("demo");

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

 array(2) {   [0]=>   array(2) {     ["name"]=>     string(4) "logs"     ["options"]=>     array(2) {       ["capped"]=>       bool(true)       ["size"]=>       int(10240)     }   }   [1]=>   array(2) {     ["name"]=>     string(5) "users"     ["options"]=>     array(1) {       ["flags"]=>       int(1)     }   } } 

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