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 indexes 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.TTL索引会在一定时间后自动从集合中删除文档。将这些索引用于只需要持续有限时间的数据,如机器生成的事件数据、日志和会话信息。
Unique Indexes唯一索引
Unique indexes cause MongoDB to reject duplicate values for the indexed field. These indexes are useful when your documents contain a unique identifier, such as a 唯一索引会导致MongoDB拒绝索引字段的重复值。当文档包含唯一标识符(如userId.userId)时,这些索引非常有用。