Saturday, 15 September 2012

Which algorithm does MongoDB use for _id -



Which algorithm does MongoDB use for _id -

this question has reply here:

how mongodb's objectids generated? 3 answers

which algorithm mongodb utilize each document _id?

i not find documentation it. kind of uuid?

objectid default type "_id" , utilize 12 bytes of storage,which gives them string representation 24 hexadecimal digits: 2 digits each byte. generated on client side.if create multiple new objectids in rapid succession, can see lastly few digits alter each time. in addition, couple of digits in middle of objectid alter (if space creations out couple of seconds). because of manner in objectids created. 12 bytes of objectid generated follows:

0|1|2|3 4|5|6 7|8| 9|10|11 timestamp machine pid increment

the first 4 bytes of objectid timestamp in seconds. provides couple of useful properties: timestamp, when combined next 5 bytes, provides uniqueness @ granularity of second.because timestamp comes first, means objectids sort in insertion order(this not strong guarantee). in these 4 bytes exists implicit timestamp of when each document created.

the next 3 bytes of objectid unique identifier of machine on generated. hash of machine’s hostname. including these bytes, guranteed different machines not generate colliding objectids.

to provide uniqueness among different processes generating objectids concurrently on single machine, next 2 bytes taken process identifier (pid) of objectid -generating process. these first 9 bytes of objectid guarantee uniqueness across machines , processes single second. lastly 3 bytes incrementing counter responsible uniqueness within sec in single process. allows 256 3 (16,777,216) unique objectids generated per process in single second.

mongodb

No comments:

Post a Comment