Navigation
This version of the documentation is archived and no longer supported. To learn how to upgrade your version of PHP Library Manual, refer to the upgrade documentation.

MongoDB\Collection::getDatabaseName()

Definition

MongoDB\Collection::getDatabaseName

Returns the name of the database containing this collection.

function getDatabaseName(): string

Return Values

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

Example

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