{
  "id": 13069815,
  "title": "MongoDB Indexing Strategies: ESR Rule, Explain Plans, and Performance Tuning",
  "url": "https://urgent.news/2026/10/09/mongodb-indexing-strategies-esr-rule-explain-plans-and-performance",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-09T08:30:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/devanshu_patil/mongodb-indexing-strategies-esr-rule-explain-plans-and-performance-tuning-3pkn"
  },
  "original_language": "en",
  "account": "MongoDB indexing is crucial for query performance. Without proper indexes, MongoDB must scan the entire collection, leading to slow responses as collections grow large. This article outlines key indexing strategies to optimize performance.\n\nSingle-field indexes index one field, allowing quick equality searches, sorting, and range queries. However, frequent writes can slow down as the index must be updated.\n\nCompound indexes combine multiple fields, but the order matters. Follow the Equality, Sort, Range (ESR) rule: put equality fields first, then sorting, and finally range fields. For example, querying orders by status, price range, and sorted by creation date would use indexes on status, createdAt, and price.\n\nTo check if queries are using indexes, run .explain(\"executionStats\") on a query. Look for IXSCAN in the output instead of COLLSCAN, which indicates index usage. Monitor metrics like totalDocsExamined vs nReturned and totalKeysExamined. A healthy ratio is close to 1:1, while high key or doc counts suggest inefficient queries.\n\nLastly, manage index storage. Too many indexes can exceed RAM, causing disk paging and slowdowns. Use $indexStats to identify unused indexes. Optimize index usage for fast, efficient queries.",
  "summary": "+05:30\" description: \"Master MongoDB indexing by diving deep into the Equality, Sort, Range (ESR) rule, analyzing explain executionStats to catch COLLSCAN, and managing index overhead.\" tags: [mongodb, database, backend, performance] ai_disclosure_level: some_ai…",
  "key_points": [
    "Single-field indexes enable quick equality searches, sorting, and range queries.",
    "Compound indexes follow the ESR rule: equality first, sorting second, range last.",
    "Monitor index usage with .explain( executionStats ) and manage index storage with $indexStats."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}