问题描述
在REST应用程序中,我需要将UUID
字符串表示形式(在json
中接收到)转换为UUID Object
,以将其存储在MongoDB的_id
字段中.我这样做是因为听说使用UUID
和String
时,查找/插入时间会有所提高.
In REST applications, I need to convert UUID
string representation (received in json
) to UUID Object
to store it on MongoDB's _id
field. I'm doing that as I heard there is a performance gain in the lookup/insertion time when using UUID
vs String
.
在MongoDB上将UUID
用作_id
而不是它的字符串表示形式时,确实确实可以提高性能吗? (即使很小的性能提升也会对我产生很大的影响)
Is there really a performance gain when using UUID
as _id
on MongoDB instead of its string representation? (even small performance gains can have a big impact for me)
PS:我看到了这篇文章表示效果对于ObjectID
更好(不完全相同,不确定是否适用于UUID
),但是唯一的原因似乎是ObjectID
与String
相比可能更小.
PS: I saw this post that says performance is better for ObjectID
(not exactly the same, not sure it applies to UUID
), but the only reason seems to be the potential smaller size of ObjectID
vs String
.
推荐答案
我正在使用将UUID
编码为BSON::Binary
的PyMongo
.
I am using PyMongo
which encode UUID
as a BSON::Binary
.
我们可以从 MongoDB文档中看到:
我的UUID
在该范围内,因此性能会比String
表示更高.
My UUID
is in that range, so the performance will be increased over the String
representation.
这篇关于在MongoDB上使用UUID而不是将其字符串表示形式为_id的性能提高了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!