- Reference >
- Database Commands >
- reIndex
reIndex¶
-
reIndex¶ The
reIndexcommand rebuilds all indexes for a specified collection. Use the following syntax:Normally, MongoDB compacts indexes during routine updates. For most users, the
reIndexcommand 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
reIndexusing the following form:Warning
This command obtains a write lock on the affected database and will block other operations until it has completed.
Note
For replica sets,
reIndexwill not propagate from the primary to secondaries.reIndexwill only affect a singlemongodinstance.