BSON Overview
BSON (Binary JSON) is a binary storage format that extends JSON’s data representation capabilities.
Data Type Support
BSON adds multiple special data types on top of JSON’s native data types:
- Date type: Used to store datetime information
- Binary Data type: Used to store binary data
- ObjectId: MongoDB-specific unique identifier
Basic Characteristics
-
Lightweight
- Compact binary encoding
- Particularly suitable for network transmission and disk storage
-
Traversability
- Retains hierarchical structure similar to JSON
- Built-in length prefix mechanism
-
Efficiency
- Encoding/decoding speed 5-10x faster than text JSON
- Supports native representation of multiple data types
BSON Types
- Double: 64-bit floating point
- String: UTF-8 encoded string
- Object: Nested BSON document
- Array: Ordered collection of values
- Binary data: Arbitrary binary data
- ObjectId: Default unique identifier for MongoDB documents
- Boolean: true or false
- Date: 64-bit integer representing milliseconds since Unix epoch
- Null: Represents null value
- Integer: 32-bit signed integer
- Timestamp: Special internal type
- Long: 64-bit signed integer
- Decimal128: 128-bit decimal floating point
- Regular Expression: Regular expression
Use Cases
- MongoDB database’s default data storage format
- Network data exchange format
- Binary data serialization