reIndex

On this page本页内容

Definition定义

reIndex

The reIndex command drops all indexes on a collection and recreates them. reIndex命令删除集合中的所有索引并重新创建它们。This operation may be expensive for collections that have a large amount of data and/or a large number of indexes.对于具有大量数据和/或大量索引的集合,此操作可能会很昂贵。

Warning警告
  • reIndex may only be run on standalone instances.只能在独立实例上运行。
  • For most users, the reIndex command is unnecessary.对于大多数用户,reIndex命令是不必要的。

Use the following syntax:使用以下语法:

{ reIndex: <collection> }

The command takes the following fields:该命令接受以下字段:

Field字段Description描述
reIndexThe name of the collection to reindex.要重新索引的集合的名称。

mongosh provides a wrapper db.collection.reIndex().提供了包装器db.collection.reIndex()

Behavior行为

For MongoDB 5.0 or later, reIndex may only be run on standalone instances.对于MongoDB 5.0或更高版本,reIndex只能在独立实例上运行。

Resource Locking资源锁定

Changed in version 4.2.2.在版本4.2.2中更改

For MongoDB 4.2.2 and later, reIndex obtains an exclusive (W) lock on the collection and blocks other operations on the collection until it completes.对于MongoDB 4.2.2及更高版本,reIndex获取集合上的独占(W)锁,并阻止集合上的其他操作,直到其完成。

For MongoDB 4.0.0 through 4.2.1, reIndex obtains a global exclusive (W) lock and blocks other operations on the mongod until it completes.对于MongoDB 4.0.0到4.2.1,reIndex获取全局独占(W)锁,并阻止mongod上的其他操作,直到其完成。

For MongoDB 3.6 and earlier, reIndex obtains an exclusive (W) lock on the database and blocks other operations on the database until finished.对于MongoDB 3.6和更早版本,reIndex获取数据库的独占(W)锁,并阻止数据库上的其他操作,直到完成。

For more information on locking in MongoDB, see FAQ: Concurrency.有关MongoDB中锁定的更多信息,请参阅常见问题解答:并发

Tip提示
See:

Index Builds on Populated Collections基于填充的集合建立索引 for more information on the behavior of indexing operations in MongoDB.有关MongoDB中索引操作行为的更多信息。

←  logRotaterenameCollection →