开发者

Getting collection names in mongodb php

Here's my db:

$db = new Mongo("mongodb://u:pw@server.com:37068/dbname")开发者_StackOverflow中文版;

I want to echo a list/array of collections (the names) on the database.

How can I do that? Thanks.


You can use listCollections: http://php.net/manual/en/mongodb.listcollections.php

<?php

$db = new Mongo("mongodb://u:pw@server.com:37068/dbname");
$list = $db->listCollections();
foreach ($list as $collection) {
    echo "$collection \n";
}

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜