Are Mongodb ObjectIds GUIDs?

guid, mongodb

Solution

Its uniqness is based upon probability. Unlike @mattexx answer:

It's not "guaranteed" to be unique because MongoDB does not enforce uniqueness to save time.

MongoDB DOES enforce uniqness on the `ObjectId`, it in fact has a unique index on the `_id` field. When talking about saving time, the `ObjectId` is historical in that manner since it was designed in the days when MongoDB did not ack any writes and needed a 99% chance of being able to insert a new unique record without the client waiting for an ack (ObjectIds are generated client side).

They are not GUIDs however they, as @Asya says, are guaranteed to have a high level of uniqness.

So long as time never moves backwards there is still a 99% chance it will be unique forever. Okay, as @Devesh says, there is a, 1 in 1 trillion (? haven't done the math), chance of even a GUID being duplicated but, again, I do not think you will reach that probability anytime soon.

Problem

The autogenerated BSON ID that is stored in the _id field of every document, is it a GUID? The documentation says its 'most likely unique', so I am a little confused. Why would they use an id that is not guaranteed to be unique?

Original source

Related problems