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

Index: Fix index alias object key position #14042

Merged
merged 3 commits into from Nov 14, 2023

Conversation

meabed
Copy link
Contributor

@meabed meabed commented Nov 2, 2023

Summary

This pr fixes an issue index object order when it has aliases, it rename the key from the alias to the original field and maintain it's position in the object as entered by user.

Examples


const UserSchema = new Schema(
  {
    n: {
      type: String,
      alias: 'name',
    },
    age: {
      type: Number,
    }
  }
)

UserSchema.index({ name: 1, age: -1 });

// The current behavior will generate index object like this 
// original fields { name: 1, age: -1 }
// after replacing the name alias with original field  { age: -1, n: 1 } ❌ 

The fix in this PR will make it work as intended and preserve the object key order
{ n: 1, age: -1 } ✅ 

This issue exist in version 7 and version 8 and would great to merge this PR in both versions.

Thank you!

@meabed meabed changed the title Fix index alias Mongoose 8: Fix index alias object key position Nov 2, 2023
@meabed meabed changed the title Mongoose 8: Fix index alias object key position Index: Fix index alias object key position Nov 2, 2023
@meabed
Copy link
Contributor Author

meabed commented Nov 3, 2023

I have fixed the linting comments 👍

@meabed
Copy link
Contributor Author

meabed commented Nov 7, 2023

Hey @vkarpov15 - Hope you well.

This is a small PR - if you could have a look and see if we could merge it in :)

Thank you 🙏

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@vkarpov15 vkarpov15 added this to the 8.0.1 milestone Nov 14, 2023
@vkarpov15 vkarpov15 merged commit 463f063 into Automattic:master Nov 14, 2023
18 checks passed
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.

None yet

2 participants