游浪踏

导航

 

1创建索引

    1是正序索引,-1是负序索引

    索引会提高查询时间按,降低插入时间

 db.books.ensureIndex({number:1})

2.创建索引,指定名称

db.book.ensureIndex({name:-1},{name:"bookname"})

3.唯一索引

db.books.ensureIndex({name:1},{unique:true})

4.剔除重复值

db.books.ensureIndex({name:1},{unique:true,dropDups:true})

5.指定索引进行查询

db.books.find({no:1}).hint({no:1})

6.查询目前是用了什么查询索引

 db.books.find({no:1}).explain()

7.产看索引

db.system.indexes.find()

8.创建索引会把表锁住,可以让创建索引放在后台进行解决

 db.books.ensureIndex({number:1},{background:true})

9.删除索引

 db.runCommand({dropIndexes:"books",index:"no_1"})

 

posted on 2017-08-11 14:49  游浪踏  阅读(103)  评论(0编辑  收藏  举报