- Reference >
- Database Commands >
- Administration Commands >
- reIndex
reIndex¶
-
reIndex¶ The
reIndexcommand 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. 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:Note
For replica sets,
reIndexwill not propagate from the primary to secondaries.reIndexwill only affect a singlemongodinstance.Important
reIndexwill rebuild indexes in the background if the index was originally specified with this option. However,reIndexwill rebuild the_idindex in the foreground, which takes the database’s write lock.
See
Index Creation for more information on the behavior of indexing operations in MongoDB.