CamelCamelCamel
CamelCamelCamel

Reputation: 5200

MongoDB :: are Mongo IDs unique across collections?

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

Upvotes: 73

Views: 25709

Answers (1)

svjson
svjson

Reputation: 2115

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.

Upvotes: 79

Related Questions