Beyond Plain JSON
MongoDB does not store documents as raw JSON text. It uses BSON, a binary serialization of JSON like documents. BSON is designed to be fast to scan and to support richer types than text JSON can express.
Types BSON Adds
- ObjectId, a 12 byte identifier used by default for the underscore id field.
- Date stored as a 64 bit millisecond timestamp.
- Int32, Int64, Double, and Decimal128 for precise numeric handling.
- Binary data, regular expressions, and embedded documents and arrays.
Why Binary Helps
- Field lengths are stored, so a reader can skip a field without parsing its contents.
- Numeric and date types are native, avoiding the ambiguity of numbers in plain JSON.
- It keeps documents compact and traversable on disk and over the wire.
When you query a field, the type matters. A number stored as Int32 will not match a query that expects a string, so consistent typing keeps indexes and comparisons predictable.
Key idea
BSON is the binary format behind MongoDB documents, adding typed values like ObjectId, Date, and Decimal128 and length prefixes that make fields fast to skip.