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()方法会将警告消息写入日志。Important
mongosh
Method方法This page documents a本页记录了一种mongoshmethod. 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关于数据库命令,请参阅reIndexcommand.reIndex命令。For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档。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()删除集合上的所有索引并重新创建它们。对于具有大量数据和/或大量索引的集合,此操作可能很昂贵。Warning
db.collection.reIndex()may only be run on standalone instances.只能在单机版实例上运行。For most users, the对于大多数用户来说,db.collection.reIndex()command is unnecessary.db.collection.reIndex()命令是不必要的。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Important
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.MongoDB Atlas集群不支持此命令。有关Atlas支持所有命令的信息,请参阅不支持的命令。
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资源锁定
db.collection.reIndex() obtains an exclusive (W) lock on the collection and blocks other operations on the collection until it completes.获取集合上的独占(W)锁,并阻止对集合的其他操作,直到它完成。
For more information on locking in MongoDB, see FAQ: Concurrency.有关MongoDB中锁定的更多信息,请参阅常见问题解答:并发。