ConFoo: Call for paper is now Open


(PECL mongo >=0.9.0)

MongoDB::listCollectionsGets an array of all MongoCollections for this database


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

Gets a list of all the collections in the database and returns them as an array of MongoCollection objects.



Include system collections.

Return Values

Returns an array of MongoCollection objects.


Version Description
1.3.0 Added the includeSystemCollections parameter.


Example #1 MongoDB::listCollections() example

The following example demonstrates running count on each collection in a database.


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

$list $db->listCollections();
foreach (
$list as $collection) {
"amount of documents in $collection: ";
$collection->count(), "\n";


The above example will output something similar to:

amount of documents in demo.pubs: 4
amount of documents in demo.elephpants: 3
amount of documents in demo.cities: 22840

See Also

add a note add a note

User Contributed Notes 1 note

George Gombay
3 months ago
For an alternative to the shell command 'show dbs', refer to my note for the listDBs() method of Mongoclient(), which reproduces some simple PHP code that will yield the names of all database present.
To Top