Docs Menu

Docs HomeMongoDB Manual

db.collection.reIndex()

On this page

  • Definition
  • Behavior
db.collection.reIndex()

Deprecated since version 6.0.

Attempting to run the db.collection.reIndex() method writes a warning message to the log.

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the reIndex command.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

The 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.

Warning

For MongoDB 5.0 or later, db.collection.reIndex() may only be run on standalone instances.

Changed in version 4.2.2.

For MongoDB 4.2.2 and later, db.collection.reIndex() obtains an exclusive (W) lock on the collection and blocks other operations on the collection until it completes.

For more information on locking in MongoDB, see FAQ: Concurrency.

Tip

See also:

←  db.collection.mapReduce()db.collection.remove() →

On this page

Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.