翻译或纠错本页面
- Indexes >
- 索引参考
索引参考¶
On this page
在 mongo shell中的索引方法¶
名称 |
描述 |
|---|---|
| db.collection.createIndex() | Builds an index on a collection. |
| db.collection.dropIndex() | 从集合中移除指定的索引 |
| db.collection.dropIndexes() | 从集合中移除所有索引 |
| db.collection.getIndexes() | 返回一个文档数组,其中描述了集合中现存的索引。 |
| db.collection.reIndex() | 重建集合中所有现存的索引 |
| db.collection.totalIndexSize() | 报告集合上索引所使用的总大小。实际上是对 collStats 命令的输出中的 totalIndexSize 键提供一层封装。 |
| cursor.explain() | Reports on the query execution plan for a cursor. |
| cursor.hint() | 强制MongoDB在查询中使用特定的索引。 |
| cursor.max() | 为游标指定索引的上界(不等于该上界,开区间)。与 cursor.hint() 配合使用 |
| cursor.min() | 为游标指定索引的下界(等于该下界,闭区间)。与 cursor.hint() 配合使用 |
| cursor.snapshot() | 强制游标使用 _id 键上的索引。可以确保游标返回每篇文档,并且每个 _id 值只会出现一次。 |
数据库中的索引命令¶
名称 |
描述 |
|---|---|
| createIndexes | 在集合中创建一个或多个索引。 |
| dropIndexes | 从集合中移除索引。 |
| compact | 对集合进行碎片整理并重建索引 |
| reIndex | 重建集合中的所有索引 |
| validate | 扫描集合中的数据和索引以检查正确性的内部命令 |
| geoNear | 执行一个能返回距离某个点最近的文档的地理查询。 |
| geoSearch | 执行一个使用MongoDB的 haystack index 功能的地理查询 |
| checkShardingIndex | 检验分片键上的索引的内部命令 |
地理查询选择器¶
名称 |
描述 |
|---|---|
| $geoWithin | Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. |
| $geoIntersects | Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects. |
| $near | Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near. |
| $nearSphere | Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere. |
