MongoDBCollection-dropIndex.txt 1.87 KB
Newer Older
1 2 3 4 5
================================
MongoDB\\Collection::dropIndex()
================================

.. default-domain:: mongodb
6

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

Definition
----------

16 17 18 19
.. phpmethod:: MongoDB\\Collection::dropIndex()

   Drop an index from the collection.

20
   .. code-block:: php
21

22 23
      function dropIndex($indexName, array $options = []): array|object

24
   This method has the following parameters:
25

26
   .. include:: /includes/apiargs/MongoDBCollection-method-dropIndex-param.rst
27 28 29

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

30 31
   .. include:: /includes/apiargs/MongoDBCollection-method-dropIndex-option.rst

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

35 36 37
An array or object with the result document of the :manual:`dropIndexes
</reference/command/dropIndexes>` 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 drops an indexes with name ``borough_1`` from the ``restaurants``
50
collection in the ``test`` database:
51 52 53 54 55

.. code-block:: php

   <?php

56
   $collection = (new MongoDB\Client)->test->restaurants;
57

58
   $result = $collection->dropIndex('borough_1');
59

60
   var_dump($result);
61

62
The output would then resemble::
63 64 65 66 67 68 69 70 71 72 73

   object(MongoDB\Model\BSONDocument)#9 (1) {
     ["storage":"ArrayObject":private]=>
     array(2) {
       ["nIndexesWas"]=>
       int(2)
       ["ok"]=>
       float(1)
     }
   }

74 75 76 77 78 79 80 81
See Also
--------

- :phpmethod:`MongoDB\\Collection::dropIndexes()`
- :doc:`/tutorial/indexes`
- :manual:`dropIndexes </reference/command/dropIndexes>` command reference in
  the MongoDB manual
- :manual:`Index documentation </indexes>` in the MongoDB manual