MongoDB

Remove and Modify a Specific Index

To remove an index, use the db.collection.dropIndex() method.

 db.users.dropIndex( { "userid": 1 } ) //removes index from userid field  

db.users.dropindexes() //removes all indexes from users collection except _id index


To modify the index, you must drop the index first and then recreate the index.

 db.users.dropIndex( { "userid": 1 } ) //removes index from userid field  

db.users.createIndex( { "userid": 1 }, { unique: true } ) //Unique Index on a Single Field

Leave a comment