MongoDB
在线手册:中文  英文

MongoDB::listCollections

(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.

参数

includeSystemCollections

Include system collections.

返回值

Returns an array of MongoCollection objects.

更新日志

版本 说明
1.3.0 Added the includeSystemCollections parameter.

范例

Example #1 MongoDB::listCollections() example

The following example demonstrates dropping each collection in a database.

<?php

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

$list $db->listCollections();
foreach (
$list as $collection) {
    echo 
"removing $collection... ";
    
$collection->drop();
    echo 
"gone\n";
}

?>

以上例程的输出类似于:

removing sample.blog.posts... gone
removing sample.critical.docs... gone
removing sample.taxes... gone
...

参见


MongoDB
在线手册:中文  英文

用户评论:

Matt Saunders (2010-01-11 08:11:25)

Currently, the PHP equivalent to "show dbs" is:
$db->command(array("listDatabases" => 1));
According to kristina1 in #mongodb, there will be a proper helper (listDatabases() I presume ) for this command in a later version.

易百教程