Lessons
MongoDB Introduction
MongoDB Installation & Setup
MongoDB Create Database & Collections
Introduction to JSON & BSON
What is JSON?
JSON (JavaScript Object Notation) is a lightweight, human-readable data format used for data exchange between web applications and servers.
It is based on key-value pairs and is easy to parse using JavaScript and other programming languages.
Example of JSON{
"name": "John Doe",
"age": 30,
"email": "john@example.com",
"hobbies": ["reading", "traveling", "coding"]
}
Features of JSON
- Text-Based - Readable by humans and machines
- Lightweight - Minimal syntax, reducing data size
- Language-Independent - Works with JavaScript, Python, PHP, Java, etc.
- Used for APIs - Common format for RESTful APIs
What is BSON?
- BSON (Binary JSON) is a binary-encoded version of JSON used primarily in MongoDB.
- It extends JSON by adding additional data types like Date, ObjectId, Binary Data, and Decimal128 for more efficient storage and retrieval.
Example\x16\x00\x00\x00 // Document Size
\x02name\x00\x09\x00\x00\x00John Doe\x00 // "name": "John Doe"
\x10age\x00\x1E\x00\x00\x00 // "age": 30
\x09createdAt\x00... // "createdAt" as BSON Date
Features of BSON
- Binary Format - Faster processing than JSON
- Efficient Storage - Short field names & optimized encoding
- Supports Additional Data Types - ObjectId, Date, Binary Data
- Used in MongoDB - MongoDB stores and retrieves data in BSON format
Difference between JSON & BSON
| Feature | JSON (JavaScript Object Notation) | BSON (Binary JSON) |
|---|---|---|
| Format | Text-based (human-readable) | Binary-based (machine-readable) |
| Speed | Slower parsing (text format) | Faster parsing (binary format) |
| Storage | Larger size (no compression) | Smaller size (optimized encoding) |
| Data Types | Supports basic types (string, number, boolean, array, object) | Supports additional types (Date, ObjectId, Binary Data, Decimal128) |
| Use Case | APIs, Config Files, Data Interchange | MongoDB Storage & Fast Querying |
Course Lessons
MongoDB Introduction
MongoDB Installation & Setup
MongoDB Create Database & Collections