Rechercher une fonction PHP

MongoDB::getCollectionInfo

(PECL mongo >=1.6.0)

MongoDB::getCollectionInfoReturns information about collections in this database

Description

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.

PHP: MongoDB::getCollectionInfo - Manual Home of Manuel PHP  Contents Haut

Parameters

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.

PHP: MongoDB::getCollectionInfo - Manual Home of Manuel PHP  Contents Haut

Return Values

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.

PHP: MongoDB::getCollectionInfo - Manual Home of Manuel PHP  Contents Haut

Errors/Exceptions

For MongoDB 2.6 and earlier, MongoException will be thrown if a non-string value was specified for the "filter" option's "name" criteria.

PHP: MongoDB::getCollectionInfo - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 MongoDB::getCollectionInfo() example

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

The above example will output something similar to:

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: MongoDB::getCollectionInfo - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-mongodb.getcollectioninfo.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut