Question

Here's my db:

$db = new Mongo("mongodb://u:pw@server.com:37068/dbname");

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

How can I do that? Thanks.

Was it helpful?

Solution

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";
}

?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top