07 / 18

How to drop an index?

Difficulty: 5/10
index management, performance optimization, migration

You may need to drop an index if you see a negative performance impact, want to replace it with a new index, or no longer need the index.

  1. 1

    You can drop any index except the default index on the _id field. To drop the _id index, you must drop the entire collection.

  2. 2

    To drop an index, you need its name. To get all index names for a collection, run the getIndexes() method

After you identify which indexes to drop, use one of the following drop methods for the specified collection:
  1. 1

    db.<collection>.dropIndex('<indexName>')

  2. 2

    db.<collection>.dropIndexes( [ '<index1>', '<index2>', '<index3>' ] )

Scenario Questions

0-2 years experience

  1. 1You have a collection with an index on the 'email' field that you no longer need. How would you remove that index using the Mongo shell?
  2. 2If you run db.users.dropIndex('email_1') and the index doesn't exist, what does MongoDB return and how would you handle it in a script?

2-5 years experience

  1. 1Your recent deployment caused a spike in write latency because an unused compound index on 'status' and 'createdAt' was still present. Walk me through how you'd identify and drop that index, and what steps you'd take to verify it didn't affect any queries.
  2. 2During a data migration, a teammate accidentally created duplicate indexes on the same field. How would you detect the redundant index and safely drop it without impacting ongoing reads?

5-8 years experience

  1. 1Our production sharded cluster has a large collection with a 200GB index that we need to drop to free disk space. Explain the strategy you would use to drop the index with minimal impact on the cluster, considering replication and balancing.
  2. 2We have a rolling upgrade process that adds new indexes and removes old ones. Describe how you would design an automated workflow to drop indexes safely across multiple replica set members, handling failures and ensuring consistency.

8+ years experience

  1. 1Our organization is standardizing index lifecycle management across dozens of services. How would you architect a cross‑team policy and tooling for deprecating and dropping indexes, including versioning, monitoring impact, and rollback procedures?
  2. 2We inherited a legacy MongoDB deployment with many stale indexes that are causing storage bloat. Outline a long‑term plan to audit, prioritize, and systematically drop these indexes while minimizing risk to SLAs and coordinating with multiple product teams.

Follow-up Questions

  • What would you check after dropping the index to ensure queries still perform as expected?
  • How would you automate index cleanup in a CI/CD pipeline?
  • Can you describe any risks if the index is being used by a secondary read preference?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.