Skip to content

DOCS-596 make drop by index name more explicit #913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions source/reference/method/db.collection.dropIndex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ db.collection.dropIndex()
:method:`db.collection.dropIndex()` method provides a wrapper around
the :dbcommand:`dropIndexes` command.

.. note::

The :method:`db.collection.dropIndex()` method cannot drop the
``_id`` index.

The :method:`db.collection.dropIndex()` method takes the following
parameter:

:param index:
Specifies the index to drop. You can specify the index either
by the index name or by the index specification document.
[#version-changed]_ See :ref:`document-index-specification`
for information on index specification documents. To view all
indexes on a collection, use the
:method:`db.collection.getIndexes()` method.

Specifies either the name or the key of the index to drop. You **must**
use the name of the index if you specified a name during the
index creation.

The :method:`db.collection.dropIndex()` method cannot drop the
``_id`` index. Use the :method:`db.collection.getIndexes()` method
to view all indexes on a collection.

Consider the following examples of the
:method:`db.collection.dropIndex()` method that assumes the
following indexes on the collection ``pets``:
The following example uses the :method:`db.collection.dropIndex()`
method on the collection ``pets`` that has the following indexes:

.. code-block:: javascript

Expand All @@ -50,19 +52,25 @@ db.collection.dropIndex()
}
]

- To drop the index on the field ``cat``, you must use the index
name ``catIdx``:
Consider the index on the field ``cat``. The index has the
user-specified name of ``catIdx`` [#index-name]_. To drop the index
``catIdx``, you can use either the index name:

.. code-block:: javascript
.. code-block:: javascript

db.pets.dropIndex( "catIdx" )

db.pets.dropIndex( 'catIdx' )
or the index specification document ``{ "cat" : 1 }``:

- To drop the index on the fields ``cat`` and ``dog``, you use
either the index name ``cat_1_dog_-1`` or the key ``{ "cat" : 1,
"dog" : -1 }``:
.. code-block:: javascript

.. code-block:: javascript
db.pets.dropIndex( { "cat" : 1 } )

db.pets.dropIndex( 'cat_1_dog_-1' )
.. [#version-changed] When using a :program:`mongo` shell version
earlier than 2.2.2, if you specified a name during the index
creation, you must use the name to drop the index.

db.pets.dropIndex( { cat : 1, dog : -1 } )
.. [#index-name] During index creation, if the user does **not**
specify an index name, the system generates the name by
concatenating the index key field and value with an underscore,
e.g. ``cat_1``.