Google News
logo
MongoDB - Interview Questions
Explain the term "Indexing" in MongoDB.
In MongoDB, indexes help in efficiently resolving queries. What an Index does is that it stores a small part of the data set in a form that is easy to traverse. The index stores the value of the specific field or set of fields, ordered by the value of the field as specified in the index. 
MongoDB’s indexes work almost identically to typical relational database indexes.
 
Indexes look at an ordered list with references to the content. These in turn allow MongoDB to query orders of magnitude faster. To create an index, use the createIndex collection method.
 
For example :
 
> db.users.find({"username": "user101"}).explain("executionStats")
 
Here, executionStats mode helps us understand the effect of using an index to satisfy queries.
Advertisement