liveBook · Manning

Schema

As explained in MongoDB 8.0 in Action, Third Edition

A schema is a specification of the fields, structures, and data types that an application's stored documents may contain.

A schema specifies the fields, structures, and data types that stored documents may contain. MongoDB permits documents in one collection to use different fields and types, so each document can carry its own structure. Flexibility supports evolving requirements and structured, unstructured, or semistructured data, but thoughtful modeling remains essential for query efficiency, scalability, and maintainability. section 5.0

Apply schema design by connecting structure to application behavior:

  • Model relationships between data entities and shape fields around the application's query patterns. section 5.0
  • Add validation when an established application requires predictable fields, formats, or data types. section 5.4
  • Review Atlas schema suggestions when nested structures, large arrays, inconsistent types, missing indexes, or high-cardinality filters affect performance. section 21.2.2

Validation rules for operational data

A users collection can require password to remain a string. A flight-routes collection can require flight_id to match an FL-plus-numbers format, airline.id to be a positive integer, and source and destination airport codes to identify actual airports. An airport collection can require total_flights to be an integer. These rules preserve expected application meaning without removing MongoDB's general schema flexibility. section 5.4

Figure 18.1 Atlas SQL interface architecture (Image © MongoDB 2024 CC BY-NC-SA 3.0)
A computer screen shot of a computer

Description automatically generated with medium confidence

Use the Atlas SQL interface architecture to trace how federated databases, virtual collections, SQL drivers, named connectors, and BI tools interact. Atlas Data Federation generates JSON-based schemas by sampling collection documents for SQL compilation and type inference. section 18.1

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains flexible structures, validation examples, generated JSON schemas, and performance recommendations without detailing validation syntax or query execution internals.
Examples
Uses user passwords, flight routes, airport totals, federated collections, nested fields, arrays, data types, and frequently queried fields.
What you can do after
Evaluate and improve MongoDB document structures, enforce selected data rules, and interpret Atlas recommendations for application workloads.
How it connects
Connects schema with data modeling, schema validation, JSON Schema, Atlas Data Federation, indexing, query patterns, and performance optimization.

Also explained in

Compare how 44 books explain schema →

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.