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.

CategoryIndex & Admin
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.<collection>.dropIndexes(<indexNames>)

⚙️ Parameters

index names arrayOptional. 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

📚 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏