Docs Menu

MongoDB\Database::getDatabaseName()

MongoDB\Database::getDatabaseName()

Returns the name of this database.

function getDatabaseName(): string

The name of this database as a string.

The following example prints the name of a database object:

<?php
$db = (new MongoDB\Client)->test;
echo $db->getDatabaseName();

The output would then resemble:

test