Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-81330

Better error message when attempting to create a descending shard key

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Sharding NYC
    • Fully Compatible
    • Sharding NYC 2023-10-30, Cluster Scalability 2023-11-13

      Shard key fields must be ascending, with at most one hashed field. Descending fields are not allowed (SERVER-8129)

      When you attempt to create one with a descending field, the error message is confusing

      [direct: mongos] test> sh.shardCollection("test.foo", {a:-1})
      MongoServerError: Shard key { a: -1 } can contain at most one 'hashed' field, and/or multiple numerical fields set to a value of 1. Failed to parse field a
      

      Can we reword this to be something like

      Shard key XXXX can contain at most one 'hashed' field, and/or multiple fields with a value of 1 (ascending). Failed to parse field a
      

      Or modify the code to have different error blocks for "more than one hashed field" and "invalid field value" to make the error message more tailored.

            Assignee:
            janna.golden@mongodb.com Janna Golden
            Reporter:
            joanna.cheng@mongodb.com Joanna Cheng
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: