liveBook · Manning

Document database

As explained in MongoDB 8.0 in Action, Third Edition

A document database stores records as self-contained documents, typically allowing each document to have a different structure.

A document database stores persistent data as documents rather than requiring every record to fit a predefined table structure. In MongoDB, documents can have different fields and data types. This makes it practical to store application objects with little transformation and to change their structure as an application evolves. section 1.1

Design documents around how the application reads and writes data. Keeping related data together can reduce the need for joins and lower retrieval costs. The trade-off is not that schemas cease to matter: you still need to decide which data belongs together based on the workload. A relational database may be a better fit when complex, precise transactions and strict data integrity dominate. section 5.1.1 section 1.1

Listing 1.1 A MongoDB document with arrays and nested documents
{
  "_id": 1,
  "title": "MongoDB 8.0 in Action",
  "publisher": "Manning Publications",
  "status": "Available",
  "focusAreas": [
    "MongoDB Database System",
    "Atlas Platform"
  ],
  "publicationYear": 2025,
  "additionalDetails": {
    "embeddedDocument": {
      "description": "A comprehensive guide to mastering
MongoDB 8.0, including working with the Atlas
Platform and learning the latest features"
    }
  }
}

This MongoDB document has ordinary fields, an array, and nested documents. Its structure illustrates how related information can be held in one record. section 1.1

Read, change, and remove documents

In the MongoDB shell, `db.books.find({ "title": "MongoDB 8.0 in Action" })` finds a matching document. Use `db.books.updateOne({ "title": "MongoDB 8.0 in Action" }, { $set: { "publisher": "Manning Publications Co" } })` to change one field, or `db.books.deleteMany({ "status": "out of print" })` to remove matching documents. Check a `deleteMany` filter carefully: it applies to every match. section 1.1

Table 5.1 The workload necessary for an application

Action

Type

Information

Frequency

Priority

Add new route.

Write

flight_id, airline (id, name, alias, iata), src_airport, dst_airport, airplane, stops, codeshare

150 per day

High

Search flight routes.

Read

src_airport, dst_airport

22,000 per day

High

Update route details.

Write

flight_id, src_airport, dst_airport, airline (name, alias, iata)

100 per day

Medium

Check route information.

Read

src_airport, dst_airport, airplane, stops

40,000 per day

High

The airline-route workload lists each action, its read or write type, fields, frequency, and priority. Use those access patterns to guide document design; frequent route lookups deserve particular attention. section 5.1.1

MongoDB stores documents as BSON, which extends JSON with types including dates and binary data. Its document model also supports scaling out through sharding, which distributes data across servers. MongoDB Atlas offers a managed deployment option. These capabilities do not replace the first design step: identify the queries the application must serve. section 1.6 section 5.1.1

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Defines the model, contrasts relational schemas, and shows basic MongoDB operations; does not detail storage internals.
Examples
Uses a nested book document, MongoDB find/update/delete commands, and an airline-route query workload.
What it assumes
Introduces persistence from application objects and contrasts relational tables; assumes familiarity with application queries when designing a workload.
What you can do after
Apply it via MongoDB by shaping documents around frequent reads and writes and performing basic document operations.
How it connects
Connects document databases to persistence, schema design, BSON, querying, and sharding.

Also explained in

Compare how 3 books explain document database →

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.