Sharded Clusters and Unique Indexes

https://docs.mongodb.com/manual/core/index-unique/#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.

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.

What is the difference?

Hi @Ke_Wei_Tan

Welcome to MongoDB community.

There is no contradiction between the two. They both say that if you must have uniqueness in _id field using default MongoDB generation it must be a prefix of the shard key. Otherwise there is possible duplicates.

If your application does not care about the _id field it is not significant for you.

Thanks
Pavel

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