On this page
dropIndexes
dropIndexes-
The
dropIndexescommand drops one or all non-_idindexes from the specified collection.The command has the following form:
{ dropIndexes: <string>, index: <string|document>, writeConcern: <document>}The command takes the following fields:
Field Description dropIndexes The name of the collection whose indexes to drop. index The name or the specification document of the index to drop.
To drop all non-
_idindexes from the collection, specify"*".To drop a text index, specify the index name.
writeConcern Optional. A document expressing the write concern of the dropcommand. Omit to use the default write concern.To drop all non-
_idindexes , specify"*"for theindex(See ref:3.6-index-asterisk).{ dropIndexes: "collection", index: "*" }To drop a single index, issue the command by specifying the name of the index you want to drop. For example, to drop the index named
age_1, use the following command:{ dropIndexes: "collection", index: "age_1" }The shell provides a useful command helper. Here’s the equivalent command:
db.collection.dropIndex("age_1");Warning
This command obtains a write lock on the affected database and will block other operations until it has completed.