Reputation: 313
I want to create an Index on Mongo database for performance perspective, so could you please help me how I can do it?
Your help will be appreciated here.
Upvotes: 19
Views: 33993
Reputation: 4417
If you want to index on field email
on users
collection:
db.users.createIndex({"email":1}, {background:true})
Before applying indexing in mongodb collections you need to understand the following aspects of indexing:
Indexing strategy:
Test your indexes:
How to index:
Keep track of indexes you create:
Measure your index usage stats in production:
Caution:
Upvotes: 42
Reputation: 3538
The basic syntax is:
db.collection.createIndex(keys, options)
So, for example:
$ db.users.createIndex({"username" : 1})
See MongoDB Indexes for the full details.
Upvotes: 14