Hi. I’m looking for Mongo functionality to search documents based on a string that will match any variation of that string ignoring capitalization and diacritics. I am using the findOne Mongo command.
To specify my use-case: I have documents with an array of names (1 or more) in each of them. Sometimes the name is written a bit differently, e.g. with an accent on one of the letters or slightly different capitalization. I will not use this functionality for long texts.
Hi @Carsten, I think the features you’re looking for can be found within the $text operator. You would need to create a text index on the field you’re attempting to query through.
According to the documentation here, you can use the $text operator on the following environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
It allows passing arguments for both your ignoring case sensitivity and diacritics.
You can find documentation on the diacritic insensitivity option here.
A caveat:
The version 3 text index is diacritic insensitive. That is, the index does not distinguish between characters that contain diacritical marks and their non-marked counterpart, such as é, ê, and e.
Once the text index is created (at least version 3) on the field, using the $text operator will be diacritic and case insensitive unless otherwise specified.