db.collection.createIndex(
{ name: 1, formula: 1, type: 1 },
{ name: "fertilizer_idx", unique: true, collation:{ locale: "en", strength: 2 } }
)
Use collation as an option for db.collection.createIndex()
more info here:
https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/
here for locale/language information:
https://docs.mongodb.com/manual/reference/collation-locales-defaults/#collation-languages-locales
strength: integer
Optional. The level of comparison to perform. Possible values are:
1: Primary level of comparison. Collation performs comparisons of the base characters only, ignoring other differences such as diacritics and case.
2: Secondary level of comparison. Collation performs comparisons up to secondary differences, such as diacritics. That is, collation performs comparisons of base characters (primary differences) and diacritics (secondary differences). Differences between base characters takes precedence over secondary differences.
3: Tertiary level of comparison. Collation performs comparisons up to tertiary differences, such as case and letter variants. That is, collation performs comparisons of base characters (primary differences), diacritics (secondary differences), and case and variants (tertiary differences). Differences between base characters takes precedence over secondary differences, which takes precedence over tertiary differences.
This is the default level.
4: Quaternary Level. Limited for specific use case to consider punctuation when levels 1-3 ignore punctuation or for processing Japanese text.
5: Identical Level. Limited for specific use case of tie breaker.
Mongo 3.4 has collation, which allows users to specify language-specific rules for string comparison
Collation includes:
collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}