重要
mongosh 方法
This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.
有关数据库命令,请参阅 reIndex 命令。
如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。
定义
db.collection.reIndex()自版本 6.0 起已弃用。
Attempting to run the
db.collection.reIndex()method writes a warning message to the log.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.警告
db.collection.reIndex()may only be run on standalone instances.For most users, the
db.collection.reIndex()command is unnecessary.
兼容性
此方法可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
重要
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
行为
For MongoDB 5.0 or later, db.collection.reIndex() may only be run on standalone instances.
资源锁定
db.collection.reIndex() 获取集合上的独占(W)锁,并阻止集合上的其他操作,直到该操作完成。
有关 MongoDB 中锁定的更多信息,请参阅常见问题解答:并发。
提示