Refer to MongoDB website: https://docs.mongodb.com/manual/reference/bson-types/
The MongoDB document store is using the BSON type, BSON (BSON short for bin-ary JSON, is a bin-ary-en-coded seri-al-iz-a-tion of Json-like Doc-u-men TS) is a binary serialization format. Classes, such as JSON, also support inline various types.
Type |
| Number
Alias |
Notes |
Double |
1 |
"Double" |
|
String |
2 |
"String" |
|
Object |
3 |
"Object" |
|
Array |
4 |
"Array" |
|
Binary data |
5 |
"Bindata" |
|
Undefined |
6 |
"Undefined" |
Deprecated. |
ObjectId |
7 |
"ObjectId" |
|
Boolean |
8 |
"BOOL" |
|
Date |
9 |
"Date" |
|
Null |
10 |
"NULL" |
|
Regular Expression |
11 |
"Regex" |
|
Dbpointer |
12 |
"Dbpointer" |
Deprecated. |
Javascript |
13 |
"JavaScript" |
|
Symbol |
14 |
"Symbol" |
Deprecated. |
JavaScript (with scope) |
15 |
"Javascriptwithscope" |
|
32-bit integer |
16 |
"Int" |
|
Timestamp |
17 |
"Timestamp" |
|
64-bit integer |
18 |
"Long" |
|
Decimal128 |
19 |
"Decimal" |
New in version 3.4. |
Min Key |
-1 |
"Minkey" |
|
Max Key |
127 |
"Maxkey" |
Several types are highlighted,
Objectid type: This is the only key that MongoDB generates like a relational DB table primary key, generating fast. This is made up of 12 bytes:
The first 4 bytes are unix seconds, 3 bytes of machine identifiers (for distributed primary keys are unique), 2 bytes of process id,3 bytes of counter number
- A 4-byte value representing the seconds since the Unix epoch,
- A 3-byte machine identifier,
- A 2-byte process ID, and
- A 3-byte counter, starting with a random value.
MongoDB was designed to be a distributed database. From the generation of the Objectid unique primary key, it deserves the reference of the Distributed System Designer.
A 3-byte machine identifier representing the different machine on which the MongoDB instance resides, and a 2-byte process ID representing a different MongoDB instance of the same machine. Plus a timestamp and a random number (3 bytes random number, the same second, theoretically can have 2^24), to a large extent, to ensure the uniqueness of the Objectid.
Introduction to MongoDB data types