DEV Community

Cover image for MongoDB Index types and Properties
sonu sharma
sonu sharma

Posted on

3 1

MongoDB Index types and Properties

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.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay