索引的分类
Single Field 单键索引
Compound Index 复合索引
Multikey Index 多键值索引
Geospatial Index 地理索引
Text Indexes 全文索引
Hashed Indexes hash索引
Unique Indexes 唯一索引
Sparse Indexed 稀疏索引
创建索引
db.collection.createIndex(
, )
1、Single Field 单键索引
db.customers.createIndex({
"age":1}
)
查询,explain() 查询计划
db.customers.find({
"age":45}
).explain()
stage:IXSCAN 使用了索引
在没有创建索引时,查询name字段
db.customers.find({
"name":"tomcat1000"}
).explain()
执行计划的信息