Introducing indexes
In order to boost the database's performance, we can use indexes to categorize the records of a collection. Thus, the database engine can perform read/write queries faster than before.
Note
Indexes support the efficient execution of queries in MongoDB. Without indexes, MongoDB must scan every document in a collection to select those documents that match the query statement. These collection scans are inefficient because they require mongod
to process a larger volume of data than an index for each operation. For more information on indexes, please visit http://docs.mongodb.org/manual/core/indexes-introduction/.
If you frequently work with specific fields in a collection, we recommend that you define an index for them to improve performance. For instance, if you sort a collection based on certain fields regularly, you can make that field an indexed field so that the database engine can perform the query much faster.
To define an index for a specific field, you can use following...