MongoDB::getCollectionInfo

(PECL mongo >=1.6.0)

MongoDB::getCollectionInfoReturns information about collections in this database

说明

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

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

Note: 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)..

    Note: 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"

    Specifies a cumulative time limit in milliseconds for processing the operation on the server (does not include idle time). If the operation is not completed by the server within the timeout period, a MongoExecutionTimeoutException will be thrown.

返回值

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.

范例

Example #1 MongoDB::getCollectionInfo() example

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

以上例程的输出类似于:

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)
    }
  }
}

参见

相关文章
php date/time 函数 returns an array with information about sunset/sunrise and twilight begin/endphp gnupg 函数 returns an array with information about all keys that matches the given patternphp firebird/interbase 函数 request information about a database serverphp mysqlnd memcache 函数 returns information about the plugin configurationphp odbc 函数 returns information about a current connectionphp rrd 函数 exports the information about rrd databasephp sqlsrv 函数 returns information about the client and specified connectionphp sqlsrv 函数 returns error and warning information about the last sqlsrv operation performedphp sqlsrv 函数 returns information about the serverphp hyperwave api 函数 returns statistics about database serverphp hyperwave api 函数 returns information about server configurationphp mongo returns information about all connection poolsphp mongocollection returns information about indexes on this collectionphp mongodb driver monitoring commandstartedevent returns the database on which the command was executedphp mongodb driver server returns an array of information about this serverphp mongodb returns information about collections in this databasephp mongodb gets an array of names for all collections in this databasephp mongodb gets an array of mongocollection objects for all collections in this databasephp mongopool returns information about all connection poolsphp rrdgraph saves the rrd database query into image and returns the verbose information about generated graph
关注编程学问公众号