MongoDB - Indexing
What is index in MongoDB ? MongoDB provides several of the best data structures for indexing, such as the classic B-tree , and other additions such as two-dimensional and spherical GeoSpatial indexes. Whenever a new collection is created, Mongo automatically c reates an index by the _id . These indexes can be found in the system.indexes collection. The following query shows all indexes in the database: >db.system.indexes.find() Most queries will include more fields than just the _id, so we need to make indexes on those fields. To increase the performance, you need to create index on display filed/s. But before that we need to check if it will improve speed or not. To check that, first check the query without an index. The explain() method is used to output details of a given operations. >db.phones.find({display: "+1 800-5650001"}).explain() { "cursor" : "BasicCursor", "nscanned" : 109999, "nscannedObjects" ...