- Importantmongosh Method
This is a
mongoshmethod. This is not the documentation for
Node.jsor other programming language specific driver methods.
For the legacy
mongoshell documentation, refer to the documentation for the corresponding MongoDB Server release:
For MongoDB API drivers, refer to the language specific MongoDB driver documentation.
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.
For MongoDB 2.6 through MongoDB versions with
featureCompatibilityVersion (fCV) set to
or earlier, MongoDB will not create an index on a collection if
the index entry for an existing document exceeds the Maximum Index Key Length.
Changed in version 4.2.2.
For MongoDB 4.2.2 and later,
an exclusive (W) lock on the collection and blocks other operations on
the collection until it completes.
For MongoDB 3.6 and earlier, these operations
db.collection.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.