The reIndex command drops all indexes on a collection and recreates them. This operation may be expensive for collections that have a large amount of data and/or a large number of indexes. Use the following syntax:

{ reIndex: "collection" }

Normally, MongoDB compacts indexes during routine updates. For most users, the reIndex command is unnecessary. However, it may be worth running if the collection size has changed significantly or if the indexes are consuming a disproportionate amount of disk space.

Call reIndex using the following form:



For replica sets, reIndex will not propagate from the primary to secondaries. reIndex will only affect a single mongod instance.


reIndex always builds indexes in the foreground due to the logic described in Multiple Index Builds.


Index Build Operations on a Populated Collection for more information on the behavior of indexing operations in MongoDB.