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

.. 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::getNamespace()

18 19 20
   Returns the :term:`namespace` of the collection. A namespace is the canonical
   name of an index or collection in MongoDB.

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

      function getNamespace(): string

25 26
Return Values
-------------
27

28
The namespace of this collection as a string.
29

30 31 32
Example
-------

33
The following returns the namespace of the ``zips`` collection in the ``test``
34
database.
35 36 37 38 39

.. code-block:: php

   <?php

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

42 43 44
   echo $collection->getNamespace();

The output would then resemble::
45

46
   test.zips
47

48 49
See Also
--------
50

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