使用ObjectId代替纯字符串的好处是什么? [英] What's the advantage of using an ObjectId instead of a plain String?

查看:77
本文介绍了使用ObjectId代替纯字符串的好处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ObjectId代替UUID作为纯字符串有什么好处?

What is the advantage to using an ObjectId instead of, say, a UUID as a plain String?

推荐答案

ObjectId是二进制的,因此占用的空间更少. ObjectId也具有排序因子-它们最终将保持插入顺序(或非常接近),同时保持唯一性.排序对某些事物可能是好的,但对其他事物却是不必要的(例如分片键).您还可以从ObjectId中提取时间戳(第二种分辨率),这很方便.

An ObjectId is binary, and thus takes up less space. ObjectIds also have the sorting factor--they will end up being in insertion order (or very close), while remaining unique. The sorting can be good for some things, but unwanted for others (like shard keys). You can also extract the timestamp (second resolution) from an ObjectId, which can be convenient.

除此之外,我会说没有太大区别.

Aside from that, I would say there's not much difference.

这篇关于使用ObjectId代替纯字符串的好处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆