Skip to content

[bug] 'duplicate index key' errors for unique lowercase fields when using RegExp filter #8333

@jbemmel

Description

@jbemmel

Fields with 'unique: true' create an index in MongoDB.
However, if a field also has 'lowercase: true', the index results in a 'duplicate key' error when updating an object using a different case

Schema: Person
name: { type: String, unique: true, lowercase: true }

create Person( name="Mike" ) => ok, name converted to 'mike'
findOneAndUpdate( { name: "Mike" }, { upsert: true } ) => Fails, duplicate key "mike"

The issue can be solved by enabling collation for the index, strength=1 to ignore case

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis issue is due to a mistake or omission in the mongoosejs.com documentation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions