Indexes in MongoDB?


Indexes in MongoDB?

Q1: What are indexes in MongoDB?
In MongoDB, indexes provide high-performance read operations for frequently used queries.
indexes special structures in MongoDB, which stores a small portion of the data set in an easy to traverse form. the index stores the value of a specific field or set of fields.
— Used to execute query efficiently.
Without indexes, MongoDB must perform a collection scan, i.e. scan every document in a
collection, to select those documents that match the query statement.
— By default, which index is created by MongoDB for every collection?
— By default, the_id collection is created for every collection by MongoDB.


Create Index

To create an index, use createIndex() method of MongoDB.


Can create index on mutliple fields



Drop an Index

Drop a particular index


Drop multiple indexes
{ "nIndexesWas" : 2, "ok" : 1 }



To check an Index

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Be the first to comment

Leave a Reply

Your email address will not be published.


10 + fourteen =