MongoDB - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

MongoDB Indexing

MongoDB Indexing

shape Description

MongoDB Indexing are used for backing up the most effective determination of objections. If MongoDB Indexing is not used in Mongodb database, then it have to browse each and every document of a set to exclusively to choose the specific document in order to contest for objection allegations. The search is very feeble and desire the mongodb to handle an expansive quantity of information. And accumulate a lot of documents and data that are shifting through them and finding the right document might start slowing the mongodb. The extraordinary information structures is said to be indexes. And these indexes keeps a bit of fragment from the information collections into cross structures. A set of values and fields will be stored inside the indexes, that are requested by the estimation of field as determined in the records. And these MongoDB Indexing can be classified into the following types

Regular(B-Tree)Index

Regular index is an index that is used in single field or multiple field values.

Geo Index

The Geo index is optimised for geographical queries, for that it doesn't have to be geography, this supports proximity of points to a center or sort by nearness or sort by proximity.

Text Index

The text index allows a client to perform search operations like parsing text queries and comparing them againt text fields.

Hashed Index

The hashed index is mainly focus on context of sharding and allows to index on certain fields, but have the key values be more evently distributed instead of clustered. These will supports sharding and allows to spread documents more evenly across the shards.

TTL Index

TTL stands for time to live index and supports expiring documents. By using these TTL index one can designate a data time field on the required document with an expiration data so that mongo will automatically remove this document from the collections when it get expired.

Ensure index()

shape Description

The ensure index() operations is used for creating an index in the mongodb database.

shape Syntax

The basic syntax for ensure index is as follows:
db.collections_name.ensure index({key:1}) Key => Name of the field 1 => Is ascending order

shape Examples

[c] >db.mycol.ensureindex({"title":1}) >db.mycol.ensureindex({"title":1,"description":-1}) [/c]

Summary

shape Key Points

  • MongoDB Indexing - Is a special type of data structures.
  • Ensure Index() - Is used for creating a new index.