MongoDB Indexing Working-Programmershelper

Spread the love


Let me explain why we use indexing.Indexing is a major element in a database.with use indexing, to increase the searching performance.using indexing, queries in MongoDB are more efficient. if few number of a document stored in a database then no problem find query working excellent.just a few second remaining to fetch data in a database.But if stored numbers of a document in a collection then find query consume too much time.because the processing power of computer uses too many resources to retire data. to decreasing time we use indexing.

Example: if 10 million document stored in the database you find one theme then this really difficult without the use of indexing.Indexing makes it easy to parsing data.


It will good to cover my below articles before this.It helps to learn more about MongoDB.In which I explained.Click here MongoDB aggregation working and MongoDB Map- reduce working.

Types of indexing in MongoDB

Single Field

MongoDB supports a single field index.the index that applies only single field.suppose we have the following document for apply indexing.

The following is the basic syntax of a single index


Alt tag MongoDB indexing

Compound Index

MongoDB indexing also supports compound index.A compound index indexing is applied more than one field.In compound index also set the order depends on the can use ascending or descending order as well.

Following is the basic syntax of a compound index


Alt tag MongoDB indexing

Multikey Index

In multi-key indexing is applied on the array.MongoDB creates a separate index for each element of an array.

The following is the of muti-ikey index


Alt tag MongoDB indexing

Text Indexes

Test index used to search string content in a document and use $ text operator.

The following is the syntax of the text index


Alt tag MongoDb indexing

Geospatial Indexes

MongoDB indexing supports the queries for the geospatial coordinate data.two special types use 2sphere and 2d indexes.

Hashed Indexes

MongoDB support hashed based indexing which used for hashed based sharding.which indexes the hash of the value of a field

The following is syntax of hashed indexes


If you want to check all the indexing that you are created.db.collection.getIndex()method used.

The following is the syntax


I wish I could tell you that a great site of just understands key element above post-MongoDB indexing. for more, detail about MongoDB indexing, please click here More detail about indexing.You also read my previous lecture.I hope you will understand this lecture.Thank you for reading this lecture. Hope you got the idea. please share it.