- Reference >
- Database Commands >
- Administration Commands >
- dropIndexes
dropIndexes¶
-
dropIndexes
¶ The
dropIndexes
command drops one or all non-_id
indexes from the specified collection.The command has the following form:
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-
_id
indexes from the collection, specify"*"
.To drop a text index, specify the index name.
writeConcern Optional. A document expressing the write concern of the drop
command. Omit to use the default write concern.
Behavior¶
Dropping an Index during Index Replication¶
Avoid dropping an index on a collection while any index is being replicated on a secondary. If you attempt to drop an index from a collection on a primary while the collection has a background index building on a secondary, reads will be halted across all namespaces and replication will halt until the background index build completes.
Examples¶
- To drop all non-
_id
indexes , specify"*"
for theindex
(See Indexes Named *).
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:
The shell provides a useful command helper. Here’s the equivalent command:
Warning
This command obtains a write lock on the affected database and will block other operations until it has completed.