MongoDB-使用12个字节的字符串作为唯一标识符而不是增量值的优势 [英] MongoDB - Advantage of using 12 bytes string as unique identifier instead of incremental value
问题描述
MongoDB生成uuid作为唯一标识符而不是将增量值作为唯一标识符有什么特殊原因吗?
Is there any specific reason for MongoDB generating uuid as unique identifier instead of incremental values as unique identifier?.
推荐答案
递增值或序列需要参考的中心点,这是缩放的限制因素. ObjectID被设计为合理的唯一ID,可以在分布式环境中独立生成,并具有单调递增的值(领先的时间戳分量)以进行近似排序.
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.
ObjectID通常是由MongoDB驱动程序生成的,因此不需要进行服务器往返操作来查找下一个可用的_id
或等待插入操作的服务器结果知道分配了什么_id
.如果驱动程序或客户端应用程序在插入文档时不包含_id
值,则mongod
服务器将生成一个ObjectID.
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.
在MongoDB中使用ObjectID并没有严格的要求:如果数据中存在更自然的唯一键,或者您希望使用替代的主键格式,则可以提供自己的_id
值.
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.
这篇关于MongoDB-使用12个字节的字符串作为唯一标识符而不是增量值的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!