MongoDB :: are Mongo IDs unique across collections?

Mongodb

Mongodb Problem Overview


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

Mongodb Solutions


Solution 1 - Mongodb

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCamelCamelCamelView Question on Stackoverflow
Solution 1 - MongodbsvjsonView Answer on Stackoverflow