MongoDB::getCollectionNames

(PECL mongo >=1.3.0)

MongoDB::getCollectionNamesGet all collections from this database

Description

public array MongoDB::getCollectionNames ([ bool $includeSystemCollections = false ] )

Returns an array of all the collection names for the given database.

Parameters

includeSystemCollections

Include system collections.

Return Values

Returns the names of the all the collections in the database as an array.

Examples

Example #1 MongoDB::getCollectionNames() example

<?php

$m 
= new Mongo;
$collections $m->selectDB("demo")->getCollectionNames();
var_dump($collections);
?>

The above example will output something similar to:

array(2) {
  [0]=>
  string(9) "addresses"
  [1]=>
  string(5) "users"
}

See Also

Коментарии

Автор:
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

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