Articles → MONGODB → Create An Index In Mongodb
Create An Index In Mongodb
Purpose
Syntax
// Create index in ascending order
db.[collection].createIndex({ field_name: 1 })
// Create index in descending order
db.[collection].createIndex({ field_name: -1 })
Example
Dropping An Index
db.[collection].dropIndex("index_name")
Get The List Of Indexes
db.[collection].getIndexes()