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

在数据浏览器中托管索引

您可以使用Data Explorer来管理集合上的索引。

To create or drop indexes, you must have access provided by at least one of the following roles:

默认情况下,最多可以有三个并发非滚动索引构建。 要学习;了解更多信息,请参阅最大并发索引构建。

如果您选择以滚动方式构建索引,您必须确保以下几点:

  • 请按顺序请求滚动索引构建和非滚动索引构建,而不要同时请求。在请求另一个索引构建之前,请等待当前正在执行的索引构建完成。

  • 如果您需要请求多个滚动索引构建,请在请求另一个滚动索引构建之前,等待当前正在执行的滚动索引构建完成。

要追踪滚动索引构建,请参阅操作日志。

For aborted rolling index builds, you must run listIndexes on each node to verify that the cancelled index no longer exists. Otherwise, the cluster might remain in an inconsistent state.

警告

由于严重问题 SERVER-68925,使用某些版本MongoDB 助手的Cloud Manager部署不应在运行以下MongoDB版本的集群上执行自动滚动索引构建:

  • MongoDB 4.2.19-4.2.22

  • MongoDB 4.4.13-4.4.16

  • MongoDB 5.0.6-5.0.11

  • MongoDB 6.0.0-6.0.1

You can continue to perform manual rolling index builds safely on your clusters. To perform automated rolling index builds safely, upgrade the MongoDB Agent to 12.4.0.7703 or later or upgrade your clusters to:

  • MongoDB 4.2.23 或更高版本

  • MongoDB 4.4.17 或更高版本

  • MongoDB 5.0.12 或更高版本

  • MongoDB 6.0.2 或更高版本

重要

滚动索引构建仅在满足特定条件时才会成功。 为确保索引构建成功,请避免使用通常会触发重启循环的以下设计模式:

以滚动方式构建索引会降低集群的弹性并增加索引构建时间。仅当常规索引构建无法满足您的需求时,我们才建议使用滚动索引构建。

注意

数据浏览器不支持以滚动方式为独立部署构建索引。

Building indexes in a rolling fashion reduces the performance impact of building indexes on replica sets and sharded clusters. To maintain cluster availability, Cloud Manager removes one node from the cluster at a time starting with a secondary.

After you build an index in a rolling fashion, if your MongoDB database runs with an FCV less than 4.2, resync the head database to ensure that the head database takes the new index into account.

Cloud Manager 会自动取消在所有节点上未成功的滚动索引构建。当滚动索引构建在某些节点上完成,但在其他节点上失败时,Cloud Manager 会取消构建并从成功构建索引的所有节点中删除索引。

在滚动索引构建取消的情况下,Cloud Manager 会生成操作日志事件,并向项目所有者发送一封包含以下信息的通知电子邮件:

  • 滚动索引构建失败的集群的名称

  • 滚动索引构建失败的命名空间

  • 包含集群和命名空间的项目

  • 包含项目的组织

  • 操作日志事件的链接

To learn more about rebuilding indexes, see Build Indexes on Replica Sets.

注意

下列索引选项无法在以滚动方式构建索引时使用:

如果您在 Options 窗格中指定这些选项,Cloud Manager 会忽略它们。

警告

数据浏览器仅显示集群中主节点 (primary node in the replica set)节点的 Usage指标。如果您的应用程序主要从从节点(secondary node from replica set)读取数据,则 Usage指标无法准确反映整个集群的索引使用情况。

For more comprehensive index usage statistics, run the $indexStats aggregation stage on each node in your cluster.

在 Collections 标签页中,您可以查看集合的索引信息。想要查看一个集合的索引信息,您需要:

1

主面板和左侧的 Namespaces 列出数据库中的集合。

2

主面板显示 Find、Indexes 和 Aggregation 视图。

3

索引表中列出了集合的索引和相关索引信息。索引信息包括索引定义、大小和使用频率。

突出显示数据浏览器中索引视图的屏幕截图。
点击放大

提示

When you create indexes, keep the ratio of reads to writes on the target collection in mind. Indexes come with a performance cost, but are more than worth the cost for frequent queries on large data sets. To learn more about indexing strategies, see Indexing Strategies.

要通过Data Explorer为集合创建索引:

1
  1. 单击要编制索引的collection。

  2. 单击collection名称下的Indexes标签页。

2

In the Create Index modal, enter the index key specification document in the Fields box:

{ <field1>: <index type>, ... }

例子

如要在字段 category (升序)和 score (降序)上创建复合索引,请指定索引规范文档:

{ category: 1, score: -1 }

For more information on indexes, see Indexes.

3
{ <option1>: <value1>, ... }

例子

要为新索引设置unique选项和name ,请输入以下文档:

{ unique: true, name: "myUniqueIndex" }
4

可以使用排序规则指定语言特定的字符串比较规则,如字母大小写和重音符号规则。排序规则文档包含 locale 字段,表示 ICU 本地代码,还可能包含用于定义排序规则行为的其他字段。

例子

以下排序规则选项文档将法语排序规则的语言环境值指定为 fr:

{ "locale": "fr" }

要查看 MongoDB 排序规则支持的区域设置列表,请参阅语言和区域设置列表。要了解有关排序规则的详情,包括默认为每个区域设置启用的排序规则选项,请参阅 MongoDB 手册的排序规则。

5
6

出现Confirm Operation模态窗口。

  • 如果索引创建正确,请单击Confirm 。 这将关闭模式并创建索引。

  • 如果索引创建看起来不正确,请单击Cancel 。 这将关闭模态窗口而不创建索引。

要通过Data Explorer从集合中删除索引:

1

选择要删除其索引的collection,然后Go到Indexes标签页。

2
3

输入索引名称进行确认,然后单击Drop 。

注意

您无法删除_id索引。