The _id information in a collection entry is really unique?

Hello,

I need to know if the _id of the entries in a collection are really unique and if there is a risk that the same _id is present in different, or a same, collections.

I plan to use this _id for an e-commerce site project, but I need to be sure that the generated _id is really unique.

I can’t find this information in the documentation.

Thanks in advance.

This is the function generating your collection documents _ids

It uses if available either

  $objId = new \MongoDB\BSON\ObjectId();

(which is what MongoDB normally uses for their _ids https://docs.mongodb.com/manual/core/index-unique/; see also Generating Globally Unique Identifiers for Use with MongoDB | MongoDB Blog )

or a “mongo db like id”, based on

  • the timestamp in ms
  • a “random” 5 char integer
  • a “random” 2-3 char integer

binaried, hashed and hexed.

Both seem to be setup to create a very unique ID in forever UNLESS you generate

*) 89000 * 990 ~ 88mill

Ok, thanks for this reply !

There is currently a bug, causing a relative high chance of duplicate IDs for MongoLite on fast import processes.

A PR with a fix was pushed ( fix (Bug 1002:createMongoDbLikeId): microsecond float to big integer … by abernh · Pull Request #1465 · agente ) and should be available soon.

There is currently a bug, causing a relative high chance of duplicate IDs for MongoLite on fast import processes.

Fixed in V 0.12.2, Sept 06, 2021