MongoDBDatabase-drop.txt 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
=========================
MongoDB\\Database::drop()
=========================

.. default-domain:: mongodb

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

Definition
----------

16 17 18
.. phpmethod:: MongoDB\\Database::drop()

   Drop the database.
19 20

   .. code-block:: php
21 22 23

      function drop(array $options = []): array|object

24
   This method has the following parameters:
25

26
   .. include:: /includes/apiargs/MongoDBDatabase-method-drop-param.rst
27 28 29

   The ``$options`` parameter supports the following options:

30 31
   .. include:: /includes/apiargs/MongoDBDatabase-method-drop-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 49 50 51 52
Example
-------

The following example drops the ``demo`` database:

.. code-block:: php

53 54
   <?php

55 56 57
   $db = (new MongoDB\Client)->demo;

   $result = $db->drop();
58

59 60 61 62 63 64 65 66 67 68 69 70 71 72
   var_dump($result);

The output would then resemble::

   object(MongoDB\Model\BSONDocument)#8 (1) {
     ["storage":"ArrayObject":private]=>
     array(2) {
       ["dropped"]=>
       string(4) "demo"
       ["ok"]=>
       float(1)
     }
   }

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

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