- Reference >
- JavaScript Methods >
- db.collection.dropIndex()
db.collection.dropIndex()¶
-
db.collection.dropIndex(index)¶ Drops or removes the specified index from a collection. The
db.collection.dropIndex()method provides a wrapper around thedropIndexescommand.Note
You cannot drop the default index on the
_idfield.The
db.collection.dropIndex()method takes the following parameter:Parameters: - index – Specifies the index to drop. You can specify the index either by
the index name or by the index specification document.
[1] See Index Specification Documents for
information on index specification documents. To view all
indexes on a collection, use the
db.collection.getIndexes()method.
The following example uses the
db.collection.dropIndex()method on the collectionpetsthat has the following indexes:Consider the index on the field
cat. The index has the user-specified name ofcatIdx[2]. To drop the indexcatIdx, you can use either the index name:or the index specification document
{ "cat" : 1 }:[1] When using a mongoshell version earlier than 2.2.2, if you specified a name during the index creation, you must use the name to drop the index.[2] 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.- index – Specifies the index to drop. You can specify the index either by
the index name or by the index specification document.
[1] See Index Specification Documents for
information on index specification documents. To view all
indexes on a collection, use the