MongoDB 索引

来源:互联网 发布:成都工业设计软件培训 编辑:程序博客网 时间:2024/06/18 18:17

索引的分类

Single Field 单键索引

Compound Index 复合索引

Multikey Index 多键值索引

Geospatial Index 地理索引

Text Indexes 全文索引

Hashed Indexes hash索引

Unique Indexes 唯一索引

Sparse Indexed 稀疏索引

创建索引

db.collection.createIndex( <key and index type specification>, <options> )

1、Single Field 单键索引

db.customers.createIndex({"age":1})

查询,explain() 查询计划

db.customers.find({"age":45}).explain()

stage:IXSCAN 使用了索引

这里写图片描述

在没有创建索引时,查询name字段

db.customers.find({"name":"tomcat1000"}).explain()

执行计划的信息

这里写图片描述

0 0
原创粉丝点击