MongoDBClient-dropDatabase.txt 1.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
===============================
MongoDB\\Client::dropDatabase()
===============================

.. default-domain:: mongodb

.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 1
   :class: singlecol

Definition
----------

16
.. phpmethod:: MongoDB\\Client::dropDatabase()
17

18
   Drop a database on the server.
19 20 21

   .. code-block:: php

22
      function dropDatabase($databaseName, array $options []): array|object
23

24
   This method has the following parameters:
25 26 27

   .. include:: /includes/apiargs/MongoDBClient-method-dropDatabase-param.rst

28
   The ``$options`` parameter supports the following options:
29 30 31

   .. include:: /includes/apiargs/MongoDBClient-method-dropDatabase-option.rst

32 33
Return Values
-------------
34

35 36 37
An array or object with the result document of the :manual:`dropDatabase
</reference/command/dropDatabase>` command. The return type will depend on the
``typeMap`` option.
38

39 40 41 42 43 44 45
Errors/Exceptions
-----------------

.. include:: /includes/extracts/error-unsupportedexception.rst
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst

46 47 48
Example
-------

49
The following example drops the ``test`` database:
50 51 52 53 54 55 56

.. code-block:: php

   <?php

   $client = new MongoDB\Client;

57
   $result = $client->dropDatabase('test');
58 59 60

   var_dump($result);

61
The output would then resemble::
62 63 64 65 66

   object(MongoDB\Model\BSONDocument)#8 (1) {
     ["storage":"ArrayObject":private]=>
     array(2) {
       ["dropped"]=>
67
       string(4) "test"
68 69 70 71 72
       ["ok"]=>
       float(1)
     }
   }

73 74
See Also
--------
75

76 77 78
- :phpmethod:`MongoDB\\Database::drop()`
- :manual:`dropDatabase </reference/command/dropDatabase>` command reference in
  the MongoDB manual