Navigation
This version of the manual is no longer supported. Learn more about upgrading your version of MongoDB.

reIndex

On this page

reIndex

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.

Warning

  • For most users, the reIndex command is unnecessary.
  • Avoid running reIndex for a replica set.
  • Do not run reIndex for a sharded cluster.

Use the following syntax:

{ reIndex: "collection" }

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

Behavior

Note

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

Important

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

See

Index Creation for more information on the behavior of indexing operations in MongoDB.

←   collMod setParameter  →