JSON vs BSON Data Types & MongoDB Internal Storage Engine (WiredTiger)0%
MongoDB Atlas Cloud Setup, Network Whitelisting & Compass GUI

JSON vs BSON Data Types & MongoDB Internal Storage Engine (WiredTiger)

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

JSON vs BSON Data Types & MongoDB Internal Storage Engine (WiredTiger)

While developers query MongoDB using familiar JavaScript/JSON notation, the database internally serializes and stores documents as BSON (Binary JSON). Behind the scenes, the WiredTiger storage engine delivers enterprise-grade performance, in-memory caching, and transparent disk compression.


1. Why Not Pure JSON? (JSON vs BSON)

Plain JSON (JavaScript Object Notation) is a lightweight text-based format, but it has severe limitations for a production database:

  1. 1
    Limited Data Types: JSON supports only strings, numbers, booleans, arrays, objects, and null. It lacks native representations for Dates, 64-bit integers, regular expressions, and raw binary bytes.
  2. 2
    Text Parsing Overhead: Text JSON requires parsing strings character-by-character on every query, which is computationally expensive.
  3. 3
    No Traversal Offsets: Finding a field in a large nested JSON document requires scanning the entire string up to that character.

BSON (Binary JSON) solves these issues:

  • Binary Encoding: Compact binary representation with prefixed length bytes for fast traversal.
  • Rich Type Support: Native ISODate, ObjectId, Decimal128 (high-precision financial arithmetic), Int64, and BinData.
Output
JSON Representation:
{"name": "Laptop", "price": 999.99, "created": "2026-09-15T00:00:00Z"}
 
BSON Storage:
\x16\x00\x00\x00\x02name\x00\x07\x00\x00\x00Laptop\x00\x01price\x00\x3d\x0a\xd7\xa3\x70\x3f\x8f\x40...

2. Anatomy of the MongoDB ObjectId

Every MongoDB document requires a unique primary key _id. If not provided, MongoDB automatically generates a 12-byte ObjectId:

Output
| 4-Byte Timestamp | 5-Byte Random Value | 3-Byte Incrementing Counter |
| (Seconds epoch) | (Process unique) | (Per-process counter) |
  • Built-in Timestamp: You can extract the exact creation timestamp of any document using doc._id.getTimestamp() without storing an extra createdAt field!
  • Natural Ordering: ObjectIds are roughly ordered chronologically.

3. The WiredTiger Storage Engine

MongoDB's default storage engine, WiredTiger, is responsible for managing data between memory and disk:

  • Document-Level Concurrency: Provides fine-grained document-level locking for write operations, maximizing multi-core CPU throughput.
  • In-Memory LRU Cache: Uses 50% of available server RAM minus 1 GB by default to cache hot indexes and documents.
  • Snappy / Zlib Compression: Transparently compresses collection data and indexes on disk, typically saving 50% to 70% of storage costs compared to raw JSON.
  • Write-Ahead Logging (Journaling): Commits write operations to an on-disk journal before flushing to data files, guaranteeing durability across sudden server power outages.

Interactive Quiz

Multiple Choice Questions

Question 1
What is BSON in MongoDB?
Question 2
How many bytes does a standard MongoDB ObjectId occupy in memory?
Question 3
What can be extracted directly from a document's default _id ObjectId without querying any other field?
Question 4
What type of concurrency locking does the WiredTiger storage engine provide for write operations?
Question 5
What role does "Journaling" play in MongoDB?

Next Lesson

MongoDB Atlas Cloud Setup, Network Whitelisting & Compass GUI

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext