对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

reIndex(数据库命令)

reIndex

自版本 6.0 起已弃用。

Attempting to run the reIndex command writes a warning message to the log.

提示

In mongosh, this command can also be run through the db.collection.reIndex() helper method.

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.

The reIndex command 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.

警告

此命令可用于以下环境中托管的部署:

重要

MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令

该命令具有以下语法:

db.runCommand(
{
reIndex: <collection>
}
)

该命令接受以下字段:

字段
说明

reIndex

要重建索引的collection的名称。

对于MongoDB5.0 或更高版本,reIndex 只能在独立运行的实例上运行。

reIndex 获取集合上的独占(W)锁,并阻止集合上的其他操作,直到该操作完成。

有关 MongoDB 中锁定的更多信息,请参阅常见问题解答:并发。

提示

基于填充集合的索引构建以了解有关 MongoDB 中索引操作行为的更多信息。

给本页内容打分