MongoDBThe basic operation of Index in MongoDB

Posted yfceshi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MongoDBThe 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.











以上是关于MongoDBThe basic operation of Index in MongoDB的主要内容,如果未能解决你的问题,请参考以下文章

MongoDBThe description of procedure in MongoDB

处理Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operatio

处理Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operatio

处理Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operatio

处理Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operatio

字符类设备