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";
}
?>
精彩评论