MongoDB
在线手册:中文 英文
PHP手册

MongoDB::listCollections

(PECL mongo >=0.9.0)

MongoDB::listCollectionsGet a list of collections in this database

说明

public array MongoDB::listCollections ( void )

参数

此函数没有参数。

返回值

Returns a list of MongoCollections.

范例

Example #1 MongoDB::listCollections() example

The following example demonstrates dropping each collection in a database.

<?php

$m 
= new Mongo();
$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
在线手册:中文 英文
PHP手册
PHP手册 - N: Get a list of collections in this database

用户评论:

Matt Saunders (11-Jan-2010 04:11)

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.