What's the advantage of using an ObjectId instead of a plain String?

前端 未结 1 1202
余生分开走
余生分开走 2020-12-17 18:35

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

相关标签:
1条回答
  • 2020-12-17 18:57

    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.

    0 讨论(0)
提交回复
热议问题