MongoDB Tutorial 0/120 lessons ~6 min read Lesson 10
BSON Explained
BSON stands for Binary JSON.
Course progress0%
Focus
5 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
BSON stands for Binary JSON. It's the serialization format MongoDB uses to store and transmit documents. BSON is a superset of JSON: it preserves all JSON types and adds binary-friendly types like ObjectId, Date, Decimal128, Binary and Timestamp.
Understanding the topic
Why BSON and not plain JSON?
- Type fidelity — distinguishes
int32,int64,double,decimal. - Native dates — stored as 64-bit ms-since-epoch, queryable with range operators.
- Binary data — store images, hashes, UUIDs efficiently.
- Traversal-friendly — length-prefixed, so the server can skip fields without parsing.
- Compact on the wire compared to text JSON.
Syntax reference
BSON-specific types you'll use often:
js
ObjectId("66f8a...") // 12-byte unique id (default _id)ISODate("2026-06-08T12:00") // dateNumberLong(9223372036854775807)NumberDecimal("19.99") // exact decimal — use for moneyUUID("xxxxxxxx-...") // standardized UUIDBinData(0, "...") // raw binary
Real-world use
When your API receives JSON and your driver serializes it to BSON, you get accurate dates and decimals automatically — no parsing bugs.
Best practices
- Always use
NumberDecimalfor currency, neverdouble. - Use
ISODatefor timestamps so range queries ($gte,$lt) work natively. - Use
UUIDwhen you need a globally unique id outside MongoDB.
Ready to mark this lesson complete?Track your journey across the entire course.