liveBook · Manning

BSON

As explained in MongoDB 8.0 in Action, Third Edition

BSON is a binary serialization format for documents that extends JSON-like data with additional types such as dates and binary data.

BSON (Binary JSON) is MongoDB’s binary-encoded format for storing JSON-like documents. It supports types beyond standard JSON, including dates and binary data, so an application can persist more than JSON alone can represent. section 1.1 section 1.6

A BSON document consists of field-and-value pairs. Values can include strings, numbers, arrays, and nested documents; documents with different fields can coexist in a collection. Keeping related information together can reduce the reads needed to retrieve it. section 2.6.4 section 1.1

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>

Run `db.grades.findOne()` in the `sample_training` database to inspect a document with an ObjectId `_id` and an array of assessment objects. The listing shows a document as displayed by the query, not its binary encoding. section 2.6.4

Keep document size in mind: a BSON document cannot exceed 16 MB. The limit prevents one document from consuming excessive RAM or transmission bandwidth. section 2.6.4

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Defines BSON, illustrates document values, and gives the 16 MB limit; does not detail the binary encoding.
Examples
Shows a `findOne()` result containing an ObjectId and an array of assessment documents.
What you can do after
Evaluate/understand MongoDB document values and the 16 MB constraint when designing stored records.
How it connects
Connects BSON to JSON, document databases, collections, nested documents, and ObjectId.

Also explained in

Compare how 2 books explain BSON →

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.