开发者

Getting collection names in mongodb php

开发者 https://www.devze.com 2023-01-27 09:17 出处:网络
Here\'s my db: $db = new Mongo(\"mongodb://u:pw@server.com:37068/dbname\")开发者_StackOverflow中文版;

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

精彩评论

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