当前位置:Gxlcms > 数据库问题 > mongodb索引(5)

mongodb索引(5)

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

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"})

 

mongodb索引(5)

标签:hint   com   mongod   man   drop   正序   重复   指定   查询   

人气教程排行