Document Database Service

Clean up unnecessary indexes

2025-07-28 03:25:50

Each index in the DDS uses a separate file for storage. If there are too many indexes in the database that are not in use or have duplicate functions, it will waste disk space to a certain extent and affect the write performance of the database.

For indexes with duplicate functions, such as the {"score": 1, "name": 1} composite index mentioned earlier, it can override the functionality of the {"score": 1} index.

Users can use mongo shell to connect to the document database instance, and then execute the following commands to check and clean it up.

  • To view the total size of all indexes for a table:

db.coll.totalIndexSize()
  • To view the size of each index:

db.coll.stats().indexSizes
  • To view the field and property information for each index:

db.coll.getIndexes()
  • To view the index creation time, usage count:

db.coll.aggregate([{$indexStats:{}}])
  • To clean up the index:

db.coll.dropIndex({a: 1})


yj5qIQAi4Zvt