MongoDB - Advantage of using 12 bytes string as unique identifier instead of incremental value

天涯浪子 提交于 2019-12-20 05:38:30

问题


Is there any specific reason for MongoDB generating uuid as unique identifier instead of incremental values as unique identifier?.


回答1:


Incrementing values or sequences require a central point of reference which is a limiting factor for scaling. ObjectIDs are designed to be reasonably unique IDs that can be independently generated in a distributed environment with monotonically increasing values (a leading timestamp component) for approximate ordering.

ObjectIDs are typically generated by MongoDB drivers so there is no need to make a server round-trip to find the next available _id or wait for the server result of an insert operation to know what _id was allocated. If a driver or client application inserts a document without including an _id value, an ObjectID will be generated by the mongod server.

There is no strict requirement to use ObjectIDs in MongoDB: you can provide your own _id values if there is a more natural unique key for your data or you prefer an alternative primary key format.



来源:https://stackoverflow.com/questions/50500641/mongodb-advantage-of-using-12-bytes-string-as-unique-identifier-instead-of-inc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!