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

Better index on Mongoid 6 / MongoDB 3.2+ #236

Open
johnnyshields opened this issue Feb 21, 2017 · 1 comment
Open

Better index on Mongoid 6 / MongoDB 3.2+ #236

johnnyshields opened this issue Feb 21, 2017 · 1 comment

Comments

@johnnyshields
Copy link
Member

johnnyshields commented Feb 21, 2017

On the Mongoid 6+ and MongoDB 3.2+ its possible to do the following index:

    index({ _slugs: 1 }, { unique: true, partial_filter_expression: { _slugs: { '$type' => 'string' } } })

This has an advantage over sparse: true because it won't consider empty array [ ] as a duplicate value (i.e. if two or more docs have _slugs: [ ]), and we could remove some unset related hacks we have.

@johnnyshields
Copy link
Member Author

You can also use this on MongoDB 3/4 if you use my https://github.com/johnnyshields/mongoid_monkey gem.

@johnnyshields johnnyshields changed the title Better index on latest Mongoid Better index on Mongoid 6 / MongoDB 3.2+ Feb 21, 2017
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

No branches or pull requests

1 participant