dropIndexes() (Drop Indexes)
Last updated: 2026-10-09
dropIndexes() (Drop Indexes)
dropIndexes() removes one or more indexes, e.g. `db.users.dropIndexes()` drops every non-_id index, or pass an array of names to drop specific ones. It also deletes all indexes prefixed by the given name (so 'age_1' pulls 'age_1_text' along). The _id index always survives. It is a common way to clean up test environments.
| Category | Index & Admin |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
db.<collection>.dropIndexes(<indexNames>)
⚙️ Parameters
| index names array | Optional. Names to drop; omit to drop every non-_id index. |
|---|
Returns:Info object with the count and status of dropped indexes.
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// dropIndexes: drop the age and email indexes
db.users.dropIndexes(['age_1', 'email_1'])
Output:
{ ok: 1, nIndexesWas: 4, nIndexesRemoved: 2 }
📌 Notes
- Omitting arguments drops every non-_id index
- Matching is by prefix, so 'age_1' also removes 'age_1_text'
- The _id index cannot be dropped
🏷️ Related Tags
💡 Related Cases
📚 Related Tutorials
❓ FAQ
QDoes dropIndexes without arguments drop every index?
AYes, everything except _id — verify the list with getIndexes() first.
QCan dropIndexes target specific indexes?
AYes, pass an array of names, e.g. db.users.dropIndexes(['age_1', 'email_1']).
QWhy does dropIndexes remove more than 'age_1'?
AIt matches by name prefix, so every index starting with 'age_1' (e.g. 'age_1_text') is removed too.