I am getting objects from below query in mongodb in variable
$dbases = $this->connection->listDatabases();
var_dump($dbases);
like
object(MongoDB\Model\DatabaseInfoLegacyIterator)#10 (1) { ["databases":"MongoDB\Model\DatabaseInfoLegacyIterator":private]=> array(5) { [0]=> array(3) { ["name"]=> string(3) "MGL" ["sizeOnDisk"]=> float(3596288) ["empty"]=> bool(false) } [1]=> array(3) { ["name"]=> string(10) "SiteStatus" ["sizeOnDisk"]=> float(32768) ["empty"]=> bool(false) } [2]=> array(3) { ["name"]=> string(5) "admin" ["sizeOnDisk"]=> float(32768) ["empty"]=> bool(false) } [3]=> array(3) { ["name"]=> string(6) "config" ["sizeOnDisk"]=> float(12288) ["empty"]=> bool(false) } [4]=> array(3) { ["name"]=> string(5) "local" ["sizeOnDisk"]=> float(73728) ["empty"]=> bool(false) } } }
I want to extract database names only like MGL,SiteStatus from this object.
Please help me in extracting them through php code. I have tried like
foreach ($dbases['databases'] as $dbs)
{
$dbname = $dbs['name'];
}
It is not working. Please help!!!
Copyright Notice:Content Author:「Nida Amin」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48262704/how-to-get-databases-names-from-listdatabases-in-mongodb