In case you want to rebuild your Index MongoDB provide the reIndex() method to do so. Sometime due to large data insertion or operation we need to rebuild the index. The syntax to rebuild all the index on a collection (table) is following:
db.collection_name.reIndex()
For example to rebuild all the Indexes of scores collection (table) we can issue the following command to MongoDB shell
db.scores.reIndex()
If you want to rebuild one specific index of collection you can use the below syntax:
db.collection_name.reIndex({field_name:1 or -1,field_name2: 1 or -1})
For example to rebuild index Smpname_1_Salary_-1 from employeeList collection we can pass the following command to MongoDB shell:
db.employeeList.reIndex({EmpName:1,Salary:-1})
How to get Started with MongoDB
How to create or drop Database in MongoDB?
How to create Collection (Table) in MongoDB?
... More