MongoDB 3.4 now includes the ability to create a true case insensitive index. This is done by setting a comparison with force 2.
Probably the easiest way to do this is to set the sort in the database itself. Then all requests inherit this sort and will use it:
db.createCollection("cities", { collation: { locale: 'en_US', strength: 2 } } ) db.cities.createIndex( { city: 1 } ) // inherits the default collation db.cities.find({city:"new york"}) //inherits default collation
Or you can do it by index by index:
db.myCollection.createIndex({city: 1}, {collation: {locale: "en", strength: 2}});
And use it as follows:
db.myCollection.find({city: "new york"}).collation({locale: "en", strength: 2});
For more information: https://jira.mongodb.org/browse/SERVER-90
user3413723
source share