What is BSON?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid MongoDB basics — a prerequisite for any developer role.

Answer

BSON (Binary JSON) is a binary-encoded serialization format used by MongoDB to store documents. It extends JSON to include additional data types and is optimized for space efficiency and traversal speed. Key differences from JSON: (1) Binary format: BSON is not human-readable like JSON but is more compact for some data types; (2) Additional types: BSON supports types not in JSON: Date (UTC datetime), ObjectId (12-byte unique ID), Binary (byte array), Decimal128 (high-precision decimal for financial data), Int32/Int64 (specific integer sizes — JSON only has generic "number"), Timestamp (internal MongoDB use), Regular Expression, Null (also in JSON), Undefined (deprecated); (3) Length-prefixed: each BSON string and document is prefixed with its length, enabling fast traversal and skipping without parsing; (4) Ordered: BSON documents preserve field order. ObjectId: MongoDB's default _id type — a 12-byte (24 hex char) unique identifier. Structure: 4-byte timestamp (seconds since epoch), 5-byte random value (unique to machine+process), 3-byte incrementing counter. ObjectIds are sortable by creation time. ObjectId("507f1f77bcf86cd799439011").getTimestamp() returns the creation time. BSON is the wire format between MongoDB driver and server, and the storage format on disk.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last MongoDB project, I used this when...' immediately makes your answer more credible and memorable.