本文介绍了在MongoDB上使用UUID而不是将其字符串表示形式为_id的性能提高了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在REST应用程序中,我需要将UUID字符串表示形式(在json中接收到)转换为UUID Object,以将其存储在MongoDB的_id字段中.我这样做是因为听说使用UUIDString时,查找/插入时间会有所提高.

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),但是唯一的原因似乎是ObjectIDString相比可能更小.

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::BinaryPyMongo.

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的性能提高了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:11