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

Reformat shardCollection to make Unique and Collations Clearer

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Catalog and Routing

      The shard collection command takes two options unique and collation that do not refer/modify the collection, but are rather options for modifying the shard key index.

      For example if I create a collection:

      use test
      db.runCommand(
         {
           create: "nonDefaultCollationCollection",
           collation: { "locale": "nl" }
         }
       )

      I've set the default collation for the collection to nl(Dutch) and the default _id index has inherited that collation. db.nonDefaultCollationCollection.getIndexes() returns:

      [
        {
          v: 2,
          key: { _id: 1 },
          name: '_id_',
          collation: {
            locale: 'nl',
            caseLevel: false,
            caseFirst: 'off',
            strength: 3,
            numericOrdering: false,
            alternate: 'non-ignorable',
            maxVariable: 'punct',
            normalization: false,
            backwards: false,
            version: '57.1'
          }
        }
      ] 

      To shard the collection on a non-_id field I am required by the server to pass a simple locale document to shardCollection.

      db.adminCommand(
         {
           shardCollection: "test.nonDefaultCollationCollection",
           key: { randomField: 1 },
           unique: true,
           collation: { locale: "simple" }
         }
       )

      Running db.nonDefaultCollationCollection.getIndexes() now shows that the index on randomField has the default simple collation due to the lack of a collation document and is enforcing uniqueness 

      [
        {
          v: 2,
          key: { _id: 1 },
          name: '_id_',
          collation: {
            locale: 'nl',
            caseLevel: false,
            caseFirst: 'off',
            strength: 3,
            numericOrdering: false,
            alternate: 'non-ignorable',
            maxVariable: 'punct',
            normalization: false,
            backwards: false,
            version: '57.1'
          }
        },
        {
          v: 2,
          key: { randomField: 1 },
          name: 'randomField_1',
          unique: true
        }
      ] 

      To enhance consistency with the create command and what is actually happening within the server when executing shardCollection the unique and collation options should be moved to an field that encapsulates both options much like the current timeseries field has multiple options currently. 

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.panton@mongodb.com Matt Panton
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: