Navigation

db.collection.reIndex()

On this page

db.collection.reIndex()

The db.collection.reIndex() 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

Behavior

Note

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

Important

Starting in MongoDB 4.0, db.collection.reIndex() takes a global exclusive (W) lock and blocks other operations on the database and all its collections until it finishes.

See also

Indexes