The specification states that the ID for a row, obtained for example in Python with
import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]
res = mycol.insert_one({"name": "John", "address": "Highway 37"})
print(res.inserted_id)
is:
a 4-byte timestamp value, representing the ObjectId’s creation, measured in seconds since the Unix epoch
a 5-byte random value
a 3-byte incrementing counter, initialized to a random value
Since:
- the timestamp value has only second-accuracy (and not milli- or microseconds)
- there is a random number after this
I understand that the lexicographical order over IDs is not useful: it does not help to know if a record has been recorded before another one (example: two records during the same second).
Question: For which reason would an "incremental counter" be useful in the context of an ID for which the previous bytes are non-incremental?
More precisely, why is: 5 random bytes + 3 incremental bytes more guaranteed to be unique than 8 random bytes / 64-bit UUID?