This is an upcoming (i.e. in progress) version of the manual.


On this page


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.


  • For most users, the reIndex command is unnecessary.

  • Avoid running reIndex for a replica set.

  • Do not run reIndex against a collection in a sharded cluster.

    Changed in version 4.2: MongoDB disallows reIndex to be run on a mongos, implementing a stronger restriction against running reIndex for a collection in a sharded cluster.

Use the following syntax:

{ reIndex: <collection>, writeConcern: <document>}

The command takes the following fields:

Field Description
reIndex The name of the collection to reindex.
writeConcern Optional. A document expressing the write concern of the drop command. Omit to use the default write concern.

The mongo shell provides a wrapper db.collection.reIndex().



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.

Starting in MongoDB 4.0, reIndex takes a global exclusive (W) lock and will block other operations until it finishes.


Index Builds on Populated Collections for more information on the behavior of indexing operations in MongoDB.