时间:2021-07-01 10:21:17 帮助过:32人阅读
| 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” |
重点介绍几个类型,
ObjectId类型:这是MongoDB生成的类似关系型DB表主键的唯一key,生成快速。具体由12个字节组成:
前4个字节是unix秒,3个字节的机器标识符(为了分布式下的主键唯一),2个字节的进程id,3个字节的计数器数字
MongoDB的设计之初就是要做分布式数据库。从ObjectId唯一主键的生成上,值得分布式系统设计人员参考。
3个字节的机器标识符,表示MongoDB实例所在机器的不同;2个字节的进程id,表示相同机器的不同MongoDB实例。再加上时间戳和随机数(3个字节随机数,同一秒上,理论上可以有2^24次个插入),很大程度上保证了ObjectId的唯一性。
MongoDB的数据类型介绍
标签:value start tar 分布式系统 tin 分布 binary and order