Skip to content

fix(schema): avoid throwing duplicate index error if index spec keys have different order or index has a custom name#15112

Merged
vkarpov15 merged 2 commits intomasterfrom
vkarpov15/gh-15109
Dec 17, 2024
Merged

fix(schema): avoid throwing duplicate index error if index spec keys have different order or index has a custom name#15112
vkarpov15 merged 2 commits intomasterfrom
vkarpov15/gh-15109

Conversation

@vkarpov15
Copy link
Collaborator

Fix #15109

Summary

#15109 points out that if index spec has keys in different order, that is still valid. So schema.index({ a: 1, b: 1 }); schema.index({ b: 1, a: 1 }) should work. Also, if there is a custom index name, then that is fine too, because MongoDB enforces index uniqueness based on name. It's just that two indexes with the same spec will have the same name unless an explicit name option is specified in the index options.

Examples

…have different order or index has a custom name

Fix #15109
@vkarpov15 vkarpov15 added this to the 8.9.2 milestone Dec 17, 2024
Co-authored-by: hasezoey <hasezoey@gmail.com>
@vkarpov15 vkarpov15 merged commit e561164 into master Dec 17, 2024
74 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-15109 branch December 17, 2024 18:30
vkarpov15 added a commit that referenced this pull request Dec 27, 2024
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.

index setting error occurred at 8.9.1("Schema already has an index")

2 participants