MongoDB :: are Mongo IDs unique across collections?

Can Mongo IDs have the same value in different collections in the same database?


Solution 1:

The uniqueness constraint for _id is per collection, so yes - one and the same ID can occur once per Collection.

It's however very unlikely, if not impossible, for the same ID to be generated twice. So in order for this to happen you would have to manually insert duplicate IDs.