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

collMod with unique/prepareUnique fails with confusing error message for FCV 5.0

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.2.0-rc0
    • Affects Version/s: 6.0.0
    • Component/s: None
    • None
    • Fully Compatible
    • Execution Team 2022-10-17, Execution Team 2022-10-31

      If your cluster is still running in FCV 5.0 mode and you follow the Convert an Existing Index to a Unique Index example, you receive the confusing error message:

      MongoServerError: collMod does not support converting an index to 'unique' or to 'prepareUnique' mode
      

      There is no mention that this could be a FCV problem, just that collMod doesn't support these operations - which it clearly does once you switch to FCV 6.0 mode.

      Repro:

      Enterprise test> db.adminCommand({setFeatureCompatibilityVersion:"5.0"})
      { ok: 1 }
      Enterprise test> db.apples.insertMany( [
      ...    { type: "Delicious", quantity: 12 },
      ...    { type: "Macintosh", quantity: 13 },
      ...    { type: "Delicious", quantity: 13 },
      ...    { type: "Fuji", quantity: 15 },
      ...    { type: "Washington", quantity: 10 },
      ... ] )
      {
        acknowledged: true,
        insertedIds: {
          '0': ObjectId("62d986221df5995914f86b4d"),
          '1': ObjectId("62d986221df5995914f86b4e"),
          '2': ObjectId("62d986221df5995914f86b4f"),
          '3': ObjectId("62d986221df5995914f86b50"),
          '4': ObjectId("62d986221df5995914f86b51")
        }
      }
      Enterprise test> db.apples.createIndex( { type: 1 } )
      type_1
      Enterprise test> db.runCommand( {
      ...     collMod: "apples",
      ...     index: {
      .....        keyPattern: { type: 1 },
      .....        prepareUnique: true
      .....     }
      ...  } )
      MongoServerError: collMod does not support converting an index to 'unique' or to 'prepareUnique' mode
      

      If we enable FCV 6.0 mode, the example now works as expected:

      Enterprise test> db.adminCommand({setFeatureCompatibilityVersion:"6.0"})
      { ok: 1 }
      Enterprise test> db.runCommand({ collMod: "apples", index: { keyPattern: { type: 1 }, prepareUnique: true } })
      { prepareUnique_old: false, prepareUnique_new: true, ok: 1 }
      

            Assignee:
            pavithra.vetriselvan@mongodb.com Pavithra Vetriselvan
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: