MongoDBCollection-getDatabaseName.txt 950 Bytes
Newer Older
1 2 3 4 5 6
======================================
MongoDB\\Collection::getDatabaseName()
======================================

.. default-domain:: mongodb

7 8 9 10 11 12
.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 1
   :class: singlecol

13 14 15 16 17
Definition
----------

.. phpmethod:: MongoDB\\Collection::getDatabaseName()

18 19
   Returns the name of the database containing this collection.

20 21 22 23
   .. code-block:: php

      function getDatabaseName(): string

24 25
Return Values
-------------
26

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

29 30 31
Example
-------

32
The following returns the database name for the ``zips`` collection in the
33
``test`` database.
34 35 36 37 38

.. code-block:: php

   <?php

39
   $collection = (new MongoDB\Client)->test->zips;
40

41 42 43
   echo $collection->getDatabaseName();

The output would then resemble::
44

45
   test
46

47 48
See Also
--------
49

50 51
- :phpmethod:`MongoDB\\Collection::getCollectionName()`
- :phpmethod:`MongoDB\\Collection::getNamespace()`
52