Indexes
- Get the statistics of query execution.
shop> db.products.find().explain("executionStats")
Get Indexes
shop> db.products.getIndexes()
[ { v: 2, key: { _id: 1 }, name: '_id_' } ]
Create Indexes
shop> db.products.createIndex({'name': 1})
- (1) for storing index in ascending order
- (-1) for storing index in descending order
Drop Index
shop> db.products.dropIndex({"name": 1})
{ nIndexesWas: 2, ok: 1 }
shop> db.products.dropIndex("name_1")
{ nIndexesWas: 2, ok: 1 }
Unique Index
db.users.createIndex({"email": 1}, {unique: true})