Closed Ob1Ju4n closed 3 weeks ago
BSON is a binary serialization format used to store documents and make remote procedure calls in MongoDB.
BSON Type | Common Use Case | Deprecated |
---|---|---|
Double (0x01) | Used to store floating-point numbers, such as prices, scientific measurements, or any data requiring decimal precision. | No |
String (0x02) | Used for storing textual data, such as names, descriptions, addresses, or any human-readable information. | No |
Object (0x03) | Used to represent embedded documents or objects in collections, which allows for storing nested or structured data. | No |
Array (0x04) | Used to store lists of values, such as a list of tags, ordered collections, or sets of related items like a user’s favorite books. | No |
Binary data (0x05) | Stores binary data, such as images, audio, video files, or encrypted data. | No |
Undefined (0x06) | Reserved for historical purposes and should not be used in modern applications. | Yes |
ObjectId (0x07) | Used to uniquely identify documents within a collection, typically as the default identifier for MongoDB documents (_id field). |
No |
Boolean (0x08) | Stores true or false values, useful for flags, toggles, or conditions such as whether a user is active or not. |
No |
Date (0x09) | Used to store dates and times, commonly used for timestamps, scheduling, or tracking document creation and modification times. | No |
Null (0x0A) | Used to represent the absence of a value, indicating that a field is not set or explicitly null. | No |
Regular expression (0x0B) | Used to store regular expressions, often used for pattern matching or filtering text fields within queries. | No |
DBPointer (0x0C) | Used to reference a document from another collection. Historically used for database references but deprecated in favor of ObjectId. | Yes |
JavaScript (0x0D) | Stores JavaScript code, typically used for server-side operations within MongoDB. | No |
Symbol (0x0E) | Used for storing symbolic identifiers, typically in legacy systems. Rarely used in modern applications; String is more commonly used now. | Yes |
JavaScript (with scope) (0x0F) | Stores JavaScript code with an associated scope, allowing the code to execute with a defined variable context. Typically used in advanced scripting scenarios. | No |
32-bit integer (0x10) | Used to store small integer values, commonly for fields like counts, small identifiers, or any number not requiring a large range. | No |
Timestamp (0x11) | Used to store special internal MongoDB timestamps, often for replication and internal operations. | No |
64-bit integer (0x12) | Used for storing large integer values, such as file sizes, large counters, or any data requiring more range than a 32-bit integer. | No |
Decimal128 (0x13) | Used for high-precision decimal numbers, such as for financial data like currencies or calculations requiring more decimal accuracy than a double. | No |
Min key (0xFF) | Represents the smallest possible BSON element, often used for internal purposes like comparing keys in indexes. | No |
Max key (0x7F) | Represents the largest possible BSON element, often used for internal purposes like comparing keys in indexes. | No |
Review the BSON data types spec and validate common use cases.