On this page本页内容
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.对于具有大量数据和/或大量索引的集合,此操作可能会很昂贵。
reIndexreIndex command is unnecessary.reIndex命令是不必要的。Use the following syntax:使用以下语法:
{ reIndex: <collection> }
The command takes the following fields:该命令接受以下字段:
reIndex |
mongosh provides a wrapper 提供了包装器db.collection.reIndex().db.collection.reIndex()。
For MongoDB 5.0 or later, 对于MongoDB 5.0或更高版本,reIndex may only be run on standalone instances.reIndex只能在独立实例上运行。
Changed in version 4.2.2.在版本4.2.2中更改。
For MongoDB 4.2.2 and later, 对于MongoDB 4.2.2及更高版本,reIndex obtains an exclusive (W) lock on the collection and blocks other operations on the collection until it completes.reIndex获取集合上的独占(W)锁,并阻止集合上的其他操作,直到其完成。
For MongoDB 4.0.0 through 4.2.1, 对于MongoDB 4.0.0到4.2.1,reIndex obtains a global exclusive (W) lock and blocks other operations on the mongod until it completes.reIndex获取全局独占(W)锁,并阻止mongod上的其他操作,直到其完成。
For MongoDB 3.6 and earlier, 对于MongoDB 3.6和更早版本,reIndex obtains an exclusive (W) lock on the database and blocks other operations on the database until finished.reIndex获取数据库的独占(W)锁,并阻止数据库上的其他操作,直到完成。
For more information on locking in MongoDB, see FAQ: Concurrency.有关MongoDB中锁定的更多信息,请参阅常见问题解答:并发。
Index Builds on Populated Collections基于填充的集合建立索引 for more information on the behavior of indexing operations in MongoDB.有关MongoDB中索引操作行为的更多信息。