{
  "id": 8426432,
  "title": "[quick-revisit]: MongoDB Indexes & B-Trees",
  "url": "https://urgent.news/2026/09/19/quick-revisit-mongodb-indexes-b-trees",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-19T09:21:41.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/mittens420/quick-revisit-mongodb-indexes-b-trees-o7h"
  },
  "original_language": "en",
  "account": "MongoDB indexes act like an index in a cookbook, allowing you to quickly locate a single document without scanning through the entire collection. An index is a data structure that stores a subset of fields, sorted, and maps them to disk locations for efficient retrieval. MongoDB uses B-Trees to organize index keys, enabling logarithmic lookup times.\n\nEvery collection automatically has a unique index on the _id field, which cannot be dropped and enforces primary key uniqueness. To prevent silent database bugs, follow four key rules:\n\n1. Understand execution stages and look for COLLSCAN (collection scan) or IXSCAN (index scan) stages. TotalDocsExamined should be significantly smaller than nReturned to avoid unnecessary data reads.\n2. Follow the ESR Rule for compound indexes: place exact match fields first, sorting fields second, and range filters last. For example, use { status: 1, age: 1 } instead of { age: 1, status: 1 }.\n3. Be cautious with embedded documents. Single-field indexes work when querying the entire object, but querying specific sub-fields can skip the index.\n4. Consider the write penalty. Indexing takes memory and requires maintenance for every insert, update, or delete operation. High read/low write workloads can benefit from aggressive indexing, while write-heavy collections should minimize indexes to avoid IOPS and storage bloat.",
  "summary": "The Mental Model A MongoDB collection without an index is like a cookbook without an index section—finding a single recipe requires flipping through all 500 pages. An index extracts a small subset of fields, sorts them, and maps them to exact disk locations so MongoDB can turn directly to the target page and jump straight to the document. The Basics An index is a specialized, memory-friendly data…",
  "key_points": [
    "MongoDB indexes function like cookbook indexes for quick document retrieval.",
    "MongoDB uses B-Trees to organize index keys for logarithmic lookup times."
  ],
  "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."
}