码迷,mamicode.com
首页 > 数据库 > 详细

【MongoDB】The basic operation of Index in MongoDB

时间:2014-10-22 01:05:29      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:database   mongodb   index   

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

bubuko.com,布布扣

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

bubuko.com,布布扣

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

标签:database   mongodb   index   

原文地址:http://blog.csdn.net/sxb0841901116/article/details/40357791

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!