当前位置:Gxlcms > 数据库问题 > MongoDB 学习笔记之 索引

MongoDB 学习笔记之 索引

时间:2021-07-01 10:21:17 帮助过:18人阅读

 

#查看执行计划

db.stu.find().explain();

#创建索引(无此列的记录也会创建索引)

db.bar.ensureIndex({content: 1})

#查看索引

db.bar.getIndexes()

 技术分享

#删除索引

db.bar.dropIndex({content: 1})

#创建多列索引

db.bar.ensureIndex({content: 1, title: -1}) 

#查询子文档

db.shop.find({‘spc.area‘:‘taiwan‘});

#子文档加索引

db.shop.ensureIndex({‘spc.area‘: 1})

#创建唯一索引

db.bar.ensureIndex({content: 1},{unique: true})

#创建稀疏索引(有列创建,无列忽略)

db.bar.ensureIndex({content: 1},{sparse: true})

注意: 在查询时,普通索引可以通过{content: null}查到,稀疏索引查不到。

#创建hash索引

db.bar.ensureIndex({content: ‘hashed‘})

#重建索引

db.bar.reIndex()

 

MongoDB 学习笔记之 索引

标签:执行   under   xpl   查看   nbsp   .com   注意   通过   drop   

人气教程排行