Navigation
This version of the documentation is archived and no longer supported.

reIndex

reIndex

The reIndex command rebuilds all indexes for a specified collection. 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:

db.collection.reIndex();

Warning

This command obtains a write lock on the affected database and will block other operations until it has completed.

Note

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

←   profile removeShard  →