-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Server
-
Labels:None
The first sentence on unique keys for sharded clusters on this link says this:
For a sharded collection, only the _id field index and the index on the shard key or a compound index where the shard key is a prefix can be unique
This implies to me that the _id field can be unique across the cluster AND the shard key can be unique as well.
Which is wrong. Within a particular shard _id can be unique. But the only index that can be truly unique across the cluster either has to be the shard key or a index that has the shard key as a prefix. We're actually depending/hoping that the _id on its own is unique without enforcing uniqueness (i.e. ObjectID is usually reliably unique).
I would rewrite this as:
For a sharded collection, only the index on the shard key or a compound index where the shard key is a prefix can be unique.
And add a warning somewhere below that specifically states that the _id can only be unique across the sharded cluster if and only if its the shard key and that when generating _id values that ObjectID or something suitably unique should be used as well.
Roy