liveBook · Manning

Dynamic mapping

As explained in MongoDB 8.0 in Action, Third Edition

Dynamic mapping is an Atlas Search index setting that automatically indexes fields discovered in documents according to inferred field types.

Dynamic mapping automatically indexes all supported fields that Atlas Search discovers in collection documents, making search setup convenient as schemas evolve. section 11.3.3

Choose dynamic mapping with these trade-offs in mind:

  • Use it for quick setup, testing, or collections whose searchable fields change frequently. section 11.3.3 section 13.5.1
  • Expect higher disk usage and possible cluster-performance impact because every dynamically indexable field is indexed. section 11.3.3
  • Prefer static mappings for production when selective indexing, efficient storage, or tighter type control matters. section 11.3.3 section 11.8

Manage the setting with Atlas Search index commands:

  • Create an index with `{ "mappings": { "dynamic": true } }`. section 11.6
  • Inspect configurations with `getSearchIndex()` or `getSearchIndexes()`. section 11.6 section 13.5.1
  • Change an existing index to static mappings with `updateSearchIndex()`, or remove it with `dropSearchIndex()`. section 11.6

Local test index

Create `LocalSearchIndex` on the `inspections` collection with `{ mappings: { dynamic: true } }`, verify that it is READY and queryable, then drop it when testing ends. section 13.5.1

Listing 11.1 Atlas Search index syntax
{
  "analyzer": "<analyzer-for-index>",
  "searchAnalyzer": "<analyzer-for-query>",
  "mappings": {
    "dynamic": <boolean>,
    "fields": { <field-definition> }
  },
  "analyzers": [ <custom-analyzer> ],
  "storedSource": <boolean> | {
    <stored-source-definition>
  },
  "synonyms": [
    {
      "name": "<synonym-mapping-name>",
      "source": {
        "collection": "<source-collection-name>"
      },
      "analyzer": "<synonym-mapping-analyzer>"
    }
  ]
}

Review the complete Atlas Search index definition shape, including `mappings.dynamic`, field definitions, analyzers, stored sources, and synonyms. section 11.3.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains automatic field discovery, resource trade-offs, static alternatives, and lifecycle commands without descending into indexing internals.
Examples
Uses the LocalSearchIndex on inspections, configuration inspection, fuzzy search, ranked results, and index deletion.
What you can do after
Operate Atlas Search indexes by creating, inspecting, updating, querying, and dropping dynamically mapped indexes.
How it connects
Connects dynamic mapping to Atlas Search indexes, static mappings, field types, analyzers, and aggregation-pipeline search.

Also explained in

Compare how 2 books explain dynamic mapping →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.