Online Snippets Library

Show all the collections in Mongodb

To Show all the collections in Mongodb, we will use MongoDB::listCollections().

Example

<?php
$m = new MongoClient('mongodb://localhost:27017');
$db = $m->manish; // manish is db name
$collections = $db->listCollections();
foreach ($collections as $collection) {
    echo "$collection \n";
}
?>