What's the advantage of using an ObjectId inst

2019-01-26 08:38发布

问题:

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

回答1:

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.



标签: mongodb