Course contentsShow
← System Design
Lesson 390 of 1,91911. NoSQL: Document StoresFree lesson

BSON Format and Data Types

Understanding MongoDB's Binary JSON format that extends JSON with additional types like dates and binary data.

BSON Format and Data Types

What you'll learn: How MongoDB uses BSON (Binary JSON) to store documents with richer data types than standard JSON.

What Is BSON?

BSON stands for Binary JSON. While you write and think about MongoDB documents as JSON-like structures with curly braces and key-value pairs, MongoDB actually stores them in BSON format under the hood. Think of BSON as JSON's more capable cousin—it looks similar but can handle types that regular JSON cannot.

Standard JSON only supports strings, numbers, booleans, arrays, objects, and null. But real applications need more: dates, binary data (like images), precise decimal numbers, and unique identifiers.

Extended Data Types in BSON

BSON adds several important types:

  • ObjectId: A 12-byte unique identifier MongoDB generates automatically for document _id fields
  • Date: True timestamp values, not just strings that look like dates
  • Binary Data: Raw bytes for storing files, encrypted data, or binary content
  • Decimal128: High-precision decimal numbers for financial calculations
  • Int32/Int64: Explicit integer types (JSON only has generic "number")
  • Timestamp: Internal type MongoDB uses for replication operations

Why Binary?

The "Binary" part means BSON encodes data in a compact binary format rather than text. This makes it faster to parse, traverse, and smaller to store—especially important when your database handles millions of documents. The tradeoff is that BSON isn't human-readable in raw form, but MongoDB drivers automatically convert between BSON and native language objects.

Key Takeaway: BSON extends JSON with native support for dates, binary data, precise numbers, and unique IDs, giving MongoDB richer type handling while maintaining JSON's intuitive document structure.