Docs HomeDevelop ApplicationsMongoDB Manual

Index Properties索引属性

Index properties affect how the query planner uses an index and how indexed documents are stored. 索引属性影响查询计划器使用索引的方式以及存储索引文档的方式。You can specify index properties as optional parameters when you create an index.创建索引时,可以将索引属性指定为可选参数。

The following sections explain the index properties that you can specify when building an index.以下部分介绍了在生成索引时可以指定的索引属性。

Note

Not all index types are compatible with all index properties.并非所有索引类型都与所有索引属性兼容。

Case-Insensitive Indexes不区分大小写的索引

Case-insensitive indexes不区分大小写的索引 support queries on strings without considering letter case.支持对字符串的查询,而不考虑字母大小写。

Hidden Indexes隐藏索引

Hidden indexes隐藏索引 are not visible to the query planner and cannot be used to support a query.查询计划器不可见,并且不能用于支持查询。

You can use hidden indexes to evaluate the potential impact of dropping an index without actually dropping it. 您可以使用隐藏索引来评估在不实际删除索引的情况下删除索引的潜在影响。If the impact is negative, you can unhide the index instead of having to recreate a dropped index. 如果影响是负面的,则可以取消隐藏索引,而不必重新创建已删除的索引。Hidden indexes are fully maintained and can be used immediately once unhidden.隐藏索引是完全维护的,一旦取消隐藏就可以立即使用。

Partial Indexes部分索引

Partial indexes分部索引 only index the documents in a collection that meet a specified filter expression. 仅对集合中符合指定筛选表达式的文档进行索引。Partial indexes have lower storage requirements and reduced performance costs for index creation and maintenance.部分索引降低了存储需求,降低了索引创建和维护的性能成本。

Partial indexes offer a superset of the functionality of sparse indexes and should be preferred over sparse indexes.部分索引提供了稀疏索引功能的超集,应该优先于稀疏索引。

Sparse Indexes稀疏索引

Sparse indexes稀疏索引 only contain entries for documents that have the indexed field. 仅包含具有索引字段的文档的条目。These indexes skip documents that do not have the indexed field.这些索引跳过没有索引字段的文档。

TTL IndexesTTL索引

TTL indexesTTL索引 automatically remove documents from a collection after a certain amount of time. 在一定时间后自动从集合中删除文档。Use these indexes for data that only needs to persist for a finite amount of time, like machine generated event data, logs, and session information.将这些索引用于只需要持续有限时间的数据,如机器生成的事件数据、日志和会话信息。

Unique Indexes唯一索引

Unique indexes唯一索引 cause MongoDB to reject duplicate values for the indexed field. 导致MongoDB拒绝索引字段的重复值。These indexes are useful when your documents contain a unique identifier, such as a userId.当文档包含唯一标识符(如userId)时,这些索引非常有用。