Skip to content

TOOLS-4071 Fix mongorestore collMod an index lacking options#883

Open
tdq45gj wants to merge 8 commits intomasterfrom
TOOLS-4071-fix-bug
Open

TOOLS-4071 Fix mongorestore collMod an index lacking options#883
tdq45gj wants to merge 8 commits intomasterfrom
TOOLS-4071-fix-bug

Conversation

@tdq45gj
Copy link
Contributor

@tdq45gj tdq45gj commented Feb 11, 2026

This commit fixes a bug that mongorestore only recognizes hidden and expireAfterSeconds options in an index collMod oplog. The change allows mongorestore to pass any collMod index options to the restored index.

@tdq45gj tdq45gj marked this pull request as ready for review February 12, 2026 19:59
@tdq45gj tdq45gj requested a review from a team as a code owner February 12, 2026 19:59
@tdq45gj tdq45gj requested review from FGasper and nickweinberger and removed request for a team and nickweinberger February 12, 2026 19:59
Copy link
Collaborator

@FGasper FGasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sort of “deny-list” approach seems out of step with our usual stance of vetting anything we send to the destination.

Discussed over DM that it should be an allow-list instead (like mongosync).

expireValue,
indexMod,
)
for k, v := range bsonutil.ToMap(indexMod) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: why ToMap here? It seems almost as easy to iterate the bson.D.

@tdq45gj tdq45gj requested a review from FGasper February 13, 2026 19:43
Copy link
Collaborator

@FGasper FGasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there’s an internal discrepancy here … ?

if expireKeyError != nil && hiddenKeyError != nil {
return errors.Errorf("must specify expireAfterSeconds or hidden: %v", indexMod)
} else {
return errors.Errorf("unknown index option: %v", k)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this logic square with the validIndexOptions in common/bsonutil/indexes.go? It seems like there are many more attributes than are listed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm following the collMod index options in the documentation. I think this differs from validIndexOptions because collMod does not support every valid index option. I tried to collMod 2dsphereIndexVersion and got an IDLUnknownField error.

@tdq45gj tdq45gj requested a review from FGasper February 13, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants