Docs Menu
Docs Home
/ / /
PHP Library Manual
/ /

MongoDB\Collection::getDatabaseName()

On this page

  • Definition
  • Return Values
  • Example
  • See Also
MongoDB\Collection::getDatabaseName()

Returns the name of the database containing this collection.

function getDatabaseName(): string

The name of the database containing this collection as a string.

The following returns the database name for the zips collection in the test database.

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

The output would then resemble:

test
  • MongoDB\Collection::getCollectionName()

  • MongoDB\Collection::getNamespace()

Back

getCollectionName()