MongoDB Index Type

Single-Field Indexes in MongoDB: How It Works and When to Use It

Stores ordered values for one document field and references matching documents. MongoDB creates a unique _id index for each collection.

What Is a Single-Field Indexes in MongoDB?

Stores ordered values for one document field and references matching documents. MongoDB creates a unique _id index for each collection.

How the Single-Field Indexes Algorithm Works

Stores ordered values for one document field and references matching documents. MongoDB creates a unique _id index for each collection.

Diagram showing the Single-Field Indexes lookup algorithm
Conceptual Single-Field Indexes algorithm. Exact behavior depends on the database version and query plan.

When to Use Single-Field Indexes

Equality, range, and sort operations on one field or nested document path.

How to Create a MongoDB Single-Field Indexes

Review data quality, existing structures, feature support, build time, and deployment requirements before creating an index on a production table.

db.products.createIndex({ sku: 1 })

Single-Field Indexes Query Example

This example demonstrates the matching query shape. Check the execution plan to confirm that the engine can use the index.

db.products.find({ sku: "A-104" })

Queries Supported by Single-Field Indexes

Equality, range, and sort operations on one field or nested document path. A similar-looking predicate may not use the same access path; operators, expressions, key order, and data type all matter.

Read Performance, Storage, and Write Costs

Indexes occupy disk/cache and add write work; low-selectivity fields may not benefit. Indexes reduce some search work but require storage and add maintenance to writes.

Single-Field Indexes Limitations and Common Mistakes

A collection scan can be cheaper when many documents match.

Do not assume that an index being present means the optimizer chose it or that the query became selective.

How to Measure and Tune Single-Field Indexes

Use explain("executionStats") to check winningPlan, keysExamined, docsExamined, and returned rows.

Compare representative plans and timings before and after, including concurrent writes and realistic data volumes.

Single-Field Indexes Questions

Will the database always use this index?

No. The optimizer weighs selectivity, estimated costs, statistics, cache state, and the amount of data returned.

What should I verify before production?

Confirm version support, query compatibility, write overhead, build/rollback procedures, and index behavior during backup and recovery.

Official MongoDB Index Documentation

Check MongoDB documentation: Index Types for release-specific requirements and supported operators.