
1 real_newbie May 27, 2011 UUID吗? 全宇宙. |
2 fzcs May 27, 2011 UUID 能保证 在人类所能认知的范围里唯一. |
3 iiduce OP |
4 tysx May 27, 2011 全宇宙唯一 |
5 mrkschan May 27, 2011 @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: 0 1 2 3 4 5 6 7 8 9 10 11 time machine pid inc 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. |
至少这个collection内啦~ 前几天我一直在为24个字符这么长的id纠结 |
7 iiduce OP |
8 mrkschan May 27, 2011 @iiduce Within the *same* mongodb process... I believe the BSON ObjectId is unique across all collections. Note: On a single machine, you can have a master mongodb process and a slave mongodb process. Thus, I have to focus the phrase - *same* mongodb process. Anyway, with this master-slave topology, write operations only occur in master mongodb process and, as a result, the ObjectIds are unique. |
10 mrkschan May 27, 2011 @ratazzi http://is.gd/Gd3yDY mongodb official documentation (english version) ... 不知道要不要跳看 (我在外的世界) |
15 mrkschan May 27, 2011 @ratazzi 我只是先前搜, 如何利用 BSON ObjectId 的 timestamp, 避免在 document 加一 create_timestamp 的 property. |
16 est May 27, 2011 全集群唯一。 |