dropIndex() (Drop an Index)
Last updated: 2026-10-09
dropIndex() (Drop an Index)
dropIndex() removes a specific index, accepting its name or key, e.g. `db.users.dropIndex('age_1')`. Dropping an index instantly degrades dependent queries to collection scans, so confirm nothing still uses it before removing it in production. The _id index cannot be dropped.
| Category | Index & Admin |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
db.<collection>.dropIndex(<indexNameOrKey>)
⚙️ Parameters
| index name or key | Index name (e.g. 'age_1') or key definition (e.g. {age: 1}). |
|---|
Returns:Result info object (with ok status).
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// dropIndex: drop the age index by key
db.users.dropIndex({ age: 1 })
Output:
{ ok: 1 }
📌 Notes
- The argument may be an index name or its key
- The _id index cannot be dropped
- Queries that relied on it degrade noticeably afterward
🏷️ Related Tags
💡 Related Cases
📚 Related Tutorials
❓ FAQ
QShould dropIndex take a name or a key?
AEither works: db.users.dropIndex('age_1') or db.users.dropIndex({age: 1}).
QWhat if I drop the wrong index?
ARecreate it with createIndex(). List indexes with getIndexes() before deleting.
QCan dropIndex remove the _id index?
ANo — the _id index is system-managed and cannot be removed.