What Is a BSON Document?
Learners will read and write BSON documents in the MongoDB shell, recognising field types like strings, numbers, arrays, and nested objects.
JSON vs BSON: The Key Difference
You write MongoDB data as familiar JSON, but it's stored as BSON — binary JSON. It's faster to scan and supports richer types like dates and ObjectId.
The Structure of a BSON Document
A BSON document is just key-value pairs in curly braces, like a JS object. Every document needs an _id, and MongoDB auto-creates a unique one if you skip it.
// A minimal MongoDB document
{
_id: ObjectId('64a2f3b1c9e7e12345678901'),
name: 'Alice',
age: 30,
active: true
}
// _id is auto-generated if omitted on insert
// ObjectId encodes the insert timestamp in its first 4 bytesAll lessons in this course
- What Is a BSON Document?
- Collections vs SQL Tables
- Databases, Collections, and Namespaces
- The mongosh Shell Essentials