Type of Indexing in MongoDB - OmIndia

Teach To India

Friday, August 03, 2018

Type of Indexing in MongoDB

Type of Indexing


Single fields Index. Single fields are simple indexes that index only one field in a collection. MongoDB can usually only use one index per query, but in some cases, the database can take advantage of more than one index to reply to a query (this is called index intersection). Also, $or actually executes more than one query at a time. Therefore, $or and $in can also use more than one index.

Compound indexes. Compound indexes are indexes that have more than one indexed field, so ideally, the most restrictive field should be to the left of the B-tree. If you want to index by sex and birth, for instance, the index should begin by birth, as it is much more restrictive than sex.


Hashed indexes. Shards use hashed indexes and create a hash according to the field value to spread the writes across the sharded instances.


GeoIndexes. GeoIndexes are a special index type that allows a search based on location, distance from a point and many other different features.


Text indexes. Text indexes can work better with indexes than a single indexed field. There are different flags we can use, like giving weights to control the results or using different collections.

 
 
 
 

No comments:

Post a Comment

Comments

Popular