mongoid - Collection ID length in MongoDB -


i new mongodb , stack overflow.

i want know why on mongodb collection id of 24 hex characters? importance of that?

why default _id 24 character hex string?

the default unique identifier generated primary key (_id) mongodb document objectid. 12 byte binary value represented 24 character hex string, , 1 of standard field types supported mongodb bson specification.

the 12 bytes of objectid constructed using:

  • a 4 byte value representing seconds since unix epoch
  • a 3 byte machine identifier
  • a 2 byte process id
  • a 3 byte counter (starting random value)

what importance of objectid?

objectids (or similar identifiers generated according guid formula) allow unique identifiers independently generated in distributed system.

the ability independently generate unique id becomes important scale multiple application servers (or perhaps multiple database nodes in sharded cluster). not want have central coordination bottleneck sequence counter (eg. might have auto-incrementing primary key), , want insert new documents without risk new identifier turn out duplicate.

an objectid typically generated mongodb client driver, can generated on mongodb server if client driver or application code or haven't added _id field.

do have use default objectid?

no. if have more suitable unique identifier use, can provide own value _id. can either single value or composite value using multiple fields.

the main constraints on _id values have unique collection , cannot update or remove _id existing document.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -