首页 > 代码库 > 【MongoDB】The basic operation of Index in MongoDB
【MongoDB】The basic operation of Index in MongoDB
In the past four blogs, we attached importance to the index, including description and comparison with usage of index. Now in this blog, we will mainly focus on the basic operation of index. such query, remove ,repair and so on.
1. View Index
getIndexes could view all the indexes in the collections.
2. Delete index
delete all the indexes: db.test.dropIndexes()
delete one index: db.test.dropIndex({name:1})
use the command to delete index:
db.runCommand({dropIndexes:"test",index:{name:1}})
3. rebuild index
db.test.reIndex() is equalant to db.runCommand({reIndex:‘test‘})
Attention:This operation need to add the lock into the document, so if the collection was filled with a large number of data, this operation would take much time.
if using repair to fix database, the database will rebuild the index.
【MongoDB】The basic operation of Index in MongoDB
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。