- Reference >
- Database Commands >
- Administration Commands >
- reIndex
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
Use the following syntax:
The command takes the following fields:
Field Description reIndex The name of the collection to reindex. The
mongo
shell provides a wrapperdb.collection.reIndex()
.
Behavior¶
Note
For replica sets, reIndex
will not propagate from the
primary to secondaries. reIndex
will
only affect a single mongod
instance.
reIndex
always builds indexes in the foreground due to the logic
described in Multiple Index Builds.
Resource Locking¶
Changed in version 4.0.
Starting in MongoDB 4.0 reIndex
obtains a global exclusive
(W) lock and blocks other operations on the mongod
until
it completes.
For MongoDB 3.6 and earlier, these operations reIndex
obtains an exclusive (W) lock on the database and blocks other
operations on the database until finished.
For more information on locking in MongoDB, see FAQ: Concurrency.
See
Index Build Operations on a Populated Collection for more information on the behavior of indexing operations in MongoDB.