Docs Home → Develop Applications → MongoDB Manual
Index Types索引类型
On this page本页内容
This page describes the types of indexes you can create in MongoDB. 本页介绍了可以在MongoDB中创建的索引类型。Different index types support different types of data and queries.不同的索引类型支持不同类型的数据和查询。
Single Field Index单个字段索引
Single field indexes collect and sort data from a single field in each document in a collection.单字段索引从集合中每个文档的单个字段中集合数据并对其进行排序。
This image shows an index on a single field, 此图显示单个字段的索引,score
:score
:
To learn more, see Single Field Indexes.要了解更多信息,请参阅单字段索引。
Compound Index复合指数
Compound indexes collect and sort data from two or more fields in each document in a collection. 复合索引从集合中每个文档的两个或多个字段中集合数据并对其进行排序。Data is grouped by the first field in the index and then by each subsequent field.数据按索引中的第一个字段分组,然后按每个后续字段分组。
For example, the following image shows a compound index where documents are first grouped by 例如,下图显示了一个复合索引,其中文档首先按userid
in ascending order (alphabetically). Then, the scores
for each userid
are sorted in descending order:userid
升序(按字母顺序)分组。然后,每个userid
的scores
按降序排列:
To learn more, see Compound Indexes.要了解更多信息,请参阅复合索引。
Multikey Index多键索引
Multikey indexes collect and sort data stored in arrays.多键索引集合和排序存储在数组中的数据。
You do not need to explicitly specify the multikey type. 您不需要显式指定多键类型。When you create an index on a field that contains an array value, MongoDB automatically sets the index to be a multikey index.当您在包含数组值的字段上创建索引时,MongoDB会自动将索引设置为多键索引。
This image shows a multikey index on the 此图显示addr.zip
field:addr.zip
字段上的多键索引:
To learn more, see Multikey Indexes.要了解更多信息,请参阅多键索引。
Geospatial Index地理空间索引
Geospatial indexes improve performance for queries on geospatial coordinate data. 地理空间索引提高了查询地理空间坐标数据的性能。To learn more, see Geospatial Indexes.要了解更多信息,请参阅地理空间索引。
MongoDB provides two types of geospatial indexes:MongoDB提供两种类型的地理空间索引:
2d indexes2d
索引that use planar geometry to return results.使用平面几何图形返回结果。2dsphere indexes2dsphere
索引that use spherical geometry to return results.使用球形几何体返回结果。
Text Index文本索引
Text indexes support text search queries on fields containing string content.文本索引支持对包含字符串内容的字段进行文本搜索查询。
To learn more, see Text Indexes.要了解更多信息,请参阅文本索引。
Use Atlas Search on Atlas Deployments在Atlas部署中使用Atlas Search
For data hosted on MongoDB Atlas, MongoDB offers a full-text search solution, Atlas Search. 对于托管在MongoDB Atlas上的数据,MongoDB提供了一个全文搜索解决方案Atlas search。Atlas Search provides improved performance and functionality compared to on-premises text search.与本地文本搜索相比,Atlas Search提供了改进的性能和功能。
Hashed Index哈希索引
Hashed indexes support hashed sharding. 哈希索引支持哈希分片。Hashed indexes index the hash of the value of a field.哈希索引对字段值的哈希进行索引。
To learn more, see Hashed Indexes.要了解更多信息,请参阅哈希索引。
Clustered Index聚集索引
New in version 5.3.
Clustered indexes specify the order in which clustered collections store data. 聚集索引指定聚集集合存储数据的顺序。Collections created with a clustered index are called clustered collections.使用聚集索引创建的集合称为聚集集合。
To learn how to create a collection with a clustered index, see Clustered Collection Examples.要了解如何使用聚集索引创建集合,请参阅聚集集合示例。