[SERVER-68206] collMod with unique/prepareUnique fails with confusing error message for FCV 5.0 Created: 21/Jul/22  Updated: 29/Oct/23  Resolved: 27/Oct/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.0.0
Fix Version/s: 6.2.0-rc0

Type: Improvement Priority: Major - P3
Reporter: James Kovacs Assignee: Pavithra Vetriselvan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Execution Team 2022-10-17, Execution Team 2022-10-31
Participants:

 Description   

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 }



 Comments   
Comment by Githook User [ 27/Oct/22 ]

Author:

{'name': 'Pavi Vetriselvan', 'email': 'pavithra.vetriselvan@mongodb.com', 'username': 'pvselvan'}

Message: SERVER-68206 Make collMod FCV related error message more clear
Branch: master
https://github.com/mongodb/mongo/commit/7553124d811c977040f18934f9404dc6305749c2

Comment by Gregory Noma [ 10/Aug/22 ]

I don't think this is specific to to collMod with unique/prepareUnique. I think most features which have a feature flag will have an error message like this if the FCV is not upgraded to where the feature flag becomes enabled by default.

Generated at Thu Feb 08 06:10:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.