liveBook · Manning

MongoDB

As explained in MongoDB 8.0 in Action, Third Edition

MongoDB is a document-oriented database platform that stores data in BSON documents and provides a database query interface.

MongoDB is a general-purpose document database for persisting application data. It stores records as BSON documents in collections. BSON extends JSON with data types such as dates and binary data; a document can contain arrays and nested documents. This makes it practical to keep related data together rather than transform every object into rows and tables. section 1.6 section 2.6.4

Documents in one collection can have different fields and data types, but a flexible schema is not a substitute for data modeling. Before production deployment, identify the application workload, map relationships, choose design patterns, and create indexes for important queries. Consider how the data and its access patterns will change. section 5.0 section 5.1

Inspect and change documents

In mongosh, select a database with `use sample_training`, then run `db.grades.findOne()` to inspect a record. Its `scores` array contains assessment documents, while `_id` identifies the record. For a books collection, `db.books.find({ "title": "MongoDB 8.0 in Action" })` retrieves matching documents; `db.books.updateOne({ "title": "MongoDB 8.0 in Action" }, { $set: { "publisher": "Manning Publications Co" } })` changes one matching document. section 2.6.4 section 1.1

The MongoDB Query API handles CRUD operations and multistage aggregation pipelines. Queries can filter, project, and sort results; aggregation can reshape data and combine collections. Indexes support efficient retrieval, while `explain()` exposes query-plan details when diagnosing a slow query. Without a suitable index, MongoDB may scan the full collection. section 1.5 section 7.8

For larger workloads, MongoDB supports scaling out through sharding, which distributes data and balances load across servers. Deployment choices include the free Community Edition, Enterprise Advanced with additional security and management capabilities, and MongoDB Atlas, a managed cloud service that simplifies setup and scaling and adds search capabilities. section 1.6 section 1.3

Listing 2.7 Displaying a single MongoDB document using findOne()
[primary] sample_training> use sample_training
already on db sample_training

[primary] sample_training> db.grades.findOne()

{
  _id: ObjectId('56d5f7eb604eb380b0d8d8ce'),
  student_id: 0,
  scores: [
    { type: 'exam', score: 78.40446309504266 },
    { type: 'quiz', score: 73.36224783231339 },
    { type: 'homework', score: 46.980982486720535 },
    { type: 'homework', score: 76.67556138656222 }
  ],
  class_id: 339
}

[primary] sample_training>

The `findOne()` result shows a complete BSON document, including its `_id` and an array of nested score records. section 2.6.4

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains document structure, schema planning, Query API operations, and index diagnosis; defers detailed CRUD and aggregation treatment.
Examples
Uses a nested book document, shell queries, a student grades record, and an airline route schema scenario.
What it assumes
Introduces document storage from application-object persistence and demonstrates basic shell operations without assuming familiarity with MongoDB tooling.
What you can do after
Apply it via mongosh to inspect and modify documents, then plan schemas and diagnose query performance with indexes and explain().
How it connects
Connects BSON documents and flexible schemas to aggregation pipelines, indexes, sharding, and MongoDB Atlas.

Also explained in

Compare how 7 books explain MongoDB →

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.