Skip to content

syncIndexes() should handle schema-level collation differences #7621

@niftylettuce

Description

@niftylettuce

I ran into an issue today where sorting on an indexed field was hitting the 32MB MongoDB memory issue.

It turns out that defining new Schema({ ..., full_name: { index: true, type: String } }, { collation: { locale: 'en' } }); doesn't automatically set the collation option on the index for full_name.

I've fixed it manually by:

> db.users.dropIndex({ full_name: 1 });
{ "nIndexesWas" : 38, "ok" : 1 }
> db.users.ensureIndex({ full_name: 1 }, { collation: { locale: 'en' } });
{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 37,
    "numIndexesAfter" : 38,
    "ok" : 1
}

However if I migrate this to another server, Mongoose doesn't set this by default, so I'd have to re-run the above script.

Is there a way to set this as a global default if collation: ... option is passed to the schema for indices?

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions