Duplicate _id in the same collection but different shards

is it possible to have 2 documents having the same _id in the same collection but different shards?

Hi @Abdullah_Alfadhel ,

It is possible to have duplicate _id documents for the same collection on different shards if _id is not a prefix of the shard key.

Per the documentation on Sharded Clusters and Unique Indexes:

If the _id field is not the shard key or the prefix of the shard key, _id index only enforces the uniqueness constraint per shard and not across shards.

For example, consider a sharded collection (with shard key {x: 1} ) that spans two shards A and B. Because the _id key is not part of the shard key, the collection could have a document with _id value 1 in shard A and another document with _id value 1 in shard B.

If the _id field is not the shard key nor the prefix of the shard key, MongoDB expects applications to enforce the uniqueness of the _id values across the shards.

Regards,
Stennie

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.