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): throw error if duplicate index definition using unique in schema path and subsequent .index() call #15093

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #15056

Summary

Defining an index using unique in schema path and later calling schema.index() causes 2 indexes to be added, which is likely a user error.

Examples

… in schema path and subsequent `.index()` call

Fix #15056
@vkarpov15 vkarpov15 requested a review from hasezoey December 13, 2024 16:22
Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

LGTM, though the lint should be fixed.

@vkarpov15 vkarpov15 merged commit be5f054 into master Dec 16, 2024
74 checks passed
@vkarpov15 vkarpov15 added this to the 8.9.1 milestone Dec 16, 2024
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-15056 branch December 16, 2024 16:37
@tonynelson19
Copy link

I think the isDeepStrictEqual check breaks compound indexes that share the same fields, since field order is important in compound indexes.

For example, it's valid to have indexes on both { a: 1, b: 1 } and { b: 1, a: 1 }, but the isDeepStrictEqual check will now throw an error since it does not consider the order of object keys when comparing objects.

@ruizmarc
Copy link

I think the isDeepStrictEqual check breaks compound indexes that share the same fields, since field order is important in compound indexes.

For example, it's valid to have indexes on both { a: 1, b: 1 } and { b: 1, a: 1 }, but the isDeepStrictEqual check will now throw an error since it does not consider the order of object keys when comparing objects.

We are just facing this issue after update. We have to compound indexes with same fields, but different order with unique tag. Since the update, mongoose is crashing

@tonynelson19
Copy link

I think compound index issues should be fixed with #15112

@mete89
Copy link

mete89 commented Dec 18, 2024

Named indexes are ignored as well which cause mongoose crashing. Expecting a release with #15112

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.

syncIndex failed creating index for the field with name 'key'
5 participants