I would like to search the collection in my mongodb database. In my collection, I have documents with a "name" field, which can be such as:
[i] "Palácio Guanabara", "Palácio da Cidade", "Festa Palácio", etc.
When the user enters a search, for example "pala" or "palá" or "Pala" or "PalÁ", all those that are in [i] should create a result set.
I found that in MongoDB I can use regex in the search, for example:
{ "name": { $regex: new Regex(".*pala.*", "i") } }
Well, this approach is case insensitive and uses percent logic from SQL ("% pala%"). But this does not ignore register accents in the database.
I found another alternative with the $ text index: https://docs.mongodb.org/manual/core/index-text/
This approach may ignore case sensitivity and accents. But "search" does not accept regular expression, so I can not search for things like "% pala%".
To summarize, I want to make the following SQL query in MongoDB:
select * from collection where remove_accents(upper(name)) like '%Pala%'
And this query returns results with the names "palácio", "palacio", "PaláCiô", etc.