For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.

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
Rate this page