Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-10517

Documentation on Unique Key for Sharded Cluster wrong

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • Server_Docs_20231030
    • 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

            Assignee:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Reporter:
            roy.rim@mongodb.com Roy Rim
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              5 years, 21 weeks, 1 day ago