Mongodb Data Types - MongoDB Tutorial
Mongodb Data Types
- MongoDB stores documents on disk in the BSON (Binary Structured Object Notation) serialization format.
- BSON is a binary representation of JSON documents, though BSON data format provides more data types than JSON.
- The mongo JavaScript shell and the MongoDB language drivers translate between BSON and the language-specific document representation.
MongoDB Data Types and Corresponding ID Number
| Type | Description | Alias | ID |
|---|---|---|---|
| Double | Represents a float value | “double” | 1 |
| String |
|
“string” | 2 |
| Object |
|
“object” | 3 |
| Array |
|
“array” | 4 |
| Binary data |
|
“binData” | 5 |
| Object id |
|
“objectId” | 7 |
| Boolean |
|
“bool” | 8 |
| Date |
|
“date” | 9 |
| Null |
|
“null” | 10 |
| Regular Expression |
|
“regex” | 11 |
| JavaScript | “javascript” | 13 | |
| Symbol |
|
“symbol” | 14 |
| JavaScript (with scope) | “javascript WithScope” |
15 | |
| 32-bit integer |
|
“int” | 16 |
| Timestamp |
|
“int” | 16 |
| 64-bit integer |
|
“long” | 18 |
| Min key |
|
“minKey” | 255 |
| Max key |
|
“maxKey” | 127 |
Comparing values of different BSON types
When comparing values of different BSON types, MongoDB uses the following comparison order, from lowest to highest :
| Order | Data Types |
|---|---|
| 1 | MinKey (internal type) |
| 2 | Null |
| 3 | Numbers (ints, longs, doubles) |
| 4 | Symbol, String |
| 5 | Object |
| 6 | Array |
| 7 | BinData |
| 8 | ObjectId |
| 9 | Boolean |
| 10 | Date, Timestamp |
| 11 | Regular Expression |