Skip to content

Better index on Mongoid 6 / MongoDB 3.2+ #236

Open
@johnnyshields

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions