MongoDB Index types and Properties

sonu sharma - Sep 6 '20 - - Dev Community

MongoDB indexes are used to improve the the performance of mongoDB read queries.

Index Types

  • Single Field

Index created on a single field of mongoDB document.

db.collection.createIndex({"scores" : 1})

  • Compound Index

Index created on more than one field of mongoDB document.

db.collection.createIndex({"scores" : 1 , "rank" : 1})

  • Multi Key Index

MongoDB uses Multi Key Index to create index on field containing array elements. MongoDB creates separate index entries for every element in array.

  • Hashed indexes

MongoDB indexes the hash of the field value.

  • Wildcard Indexes

MongoDB uses these to create index entries on the dynamic field of collection.

Index Properties

  • Unique Indexes

Restricts users to create duplicate entries of document containing indexed field.

  • Partial Indexes

Only index the document satisfying the expression provided.

  • Sparse Indexes

Only create enteries for the document containing the indexed field.

  • TTL Indexes

Automatically removes document from a collection.

  • Hidden Indexes

Used to hide the existing indexes. User can validate the impact of dropping an index without actually dropping an index.

. . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player