Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 17, 2024

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
lib/helpers/indexes/isIndexSpecEqual.js Outdated Show resolved Hide resolved
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
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