日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mongodb的id的唯一性_mongodb中的objectid是collection中唯一,还是全db唯一,还是全宇宙唯一?...

發布時間:2023/12/19 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mongodb的id的唯一性_mongodb中的objectid是collection中唯一,还是全db唯一,还是全宇宙唯一?... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

5

2011-05-27 19:26:00 +08:00

@iiduce 你已提過了...

ObjectID = 32bit timestamp + md5(hostname) + process-id + sequence-no. (Full definition is quoted at bottom of this post)

在不同電腦內, process-id 跟 sequence-no 跟 timestamp 是有機會一樣的

跟據 wikipedia (http://is.gd/yZBK2B) md5 hash 不是 collision resistance.

即是說, 是有機會出現 md5(hostname_A) == md5(hostname_B).

所以, ObjectId 一定不是全宇宙唯一.

----

BSON ObjectID Specification (http://is.gd/XcorBb)

A BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields must be stored big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure a mostly increasing order. Here's the schema:

0123456 7891011

timemachine pidinc

Here is a breakdown of the sections:

TimeStamp

This is a unix style timestamp. It is a signed int representing the number of seconds before or after January 1st 1970 (UTC).

Machine

This is the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the virtual machine id.

Pid

This is 2 bytes of the process id (or thread id) of the process generating the object id.

Increment

This is an ever incrementing value, or a random number if a counter can't be used in the language/runtime.

總結

以上是生活随笔為你收集整理的mongodb的id的唯一性_mongodb中的objectid是collection中唯一,还是全db唯一,还是全宇宙唯一?...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。