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

reIndex(数据库命令)

reIndex

自版本 6.0 起已弃用。

尝试运行reIndex 命令会将警告消息写入日志。

提示

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.

reIndex命令删除集合上的所有索引并重新创建它们。对于具有大量数据和/或大量索引的集合,此操作的开销可能很大。

警告

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

重要

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

该命令具有以下语法:

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

该命令接受以下字段:

字段
说明

reIndex

要重建索引的collection的名称。

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

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

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

提示

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

给本页内容打分