db.collection.reIndex()
On this page本页内容
Definition定义
db.collection.reIndex()
Deprecated since version 6.0.自6.0版以来已弃用。Attempting to run the试图运行db.collection.reIndex()
method writes a warning message to the log.db.collection.reIndex()
方法会在日志中写入警告消息。Importantmongosh Method
This page documents a本页记录了一个mongosh
method. This is not the documentation for database commands or language-specific drivers, such as Node.js.mongosh
方法。这不是数据库命令或特定语言驱动程序(如Node.js)的文档。For the database command, see the有关数据库命令,请参阅reIndex
command.reIndex
命令。For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档。For the legacy对于遗留的mongoshell文档,请参阅相应MongoDB Server版本的文档:mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:Thedb.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.db.collection.reIndex()
会删除集合上的所有索引并重新创建它们。对于具有大量数据和/或大量索引的集合,此操作可能代价高昂。Warningdb.collection.reIndex()
may only be run on standalone instances.只能在独立实例上运行。For most users, the对于大多数用户来说,db.collection.reIndex()
command is unnecessary.db.collection.reIndex()
命令是不必要的。
Behavior行为
For MongoDB 5.0 or later, 对于MongoDB 5.0或更高版本,db.collection.reIndex()
may only be run on standalone instances.db.collection.reIndex()
只能在独立实例上运行。
Resource Locking资源锁定
Changed in version 4.2.2.4.2.2版更改。
For MongoDB 4.2.2 and later, 对于MongoDB 4.2.2及更高版本,db.collection.reIndex()
obtains an exclusive (W) lock on the collection and blocks other operations on the collection until it completes.db.collection.reIndex()
获得集合上的独占(W)锁,并阻止集合上的其他操作,直到它完成为止。
For more information on locking in MongoDB, see FAQ: Concurrency.有关MongoDB中锁定的更多信息,请参阅常见问题解答:并发。