MongoDB

Show indexes on a MongoDB

If you want raw access to the indexes, you can query the db.system.indexes collection:

db.system.indexes.find()

To find the indexes for a specific collection, you can do:

db.collection.getIndexes()

To create an index, use

db.collection.ensureIndex({"fieldname":1})

On a large dataset, this can take sometime, so you can run it as a background process.

db.collection.ensureIndex({"fieldname":1},{"background":1})

done

Leave a Reply