In MongoDB "db.foo.find()" syntax, how can I tell it to match all letters and their accented versions?
For example, if I have a list of names in my database:
João
François
Jesús
How would I allow a search for the strings "Joao", "Francois", or "Jesus" to match the given name?
I am hoping that I don't have to do a search like this every time:
db.names.find({name : /Fr[aã...][nñ][cç][all accented o characters][all accented i characters]s/ })
As of Mongo 3.2, you can use $text
and set $diacriticSensitive
to false:
{
$text:
{
$search: <string>,
$language: <string>,
$caseSensitive: <boolean>,
$diacriticSensitive: <boolean>
}
}
See more in the Mongo docs: https://docs.mongodb.com/manual/reference/operator/query/text/