Using accentuation

Hello Everybody!

Is there a way using minimongo on de client side to search ignoring accentuation in mongo?


  • In DB: ação
  • In the search input: acao

So, the search should return the object “ação”. The oposite (acao in DB and ação in search input) should return object “acao” either.

Thanks a lot in advance!

One solution for client-side filtering is to save a version of the content with all non-ascii characters replaced by its ascii counterpart

But the opposite? DB with accentuation and my search without?

Replace the input with the corresponding ascii characters

I did it… But and when the accents are in the database (mongo)?

Imagine that in the database has an object field with word “ação”.

I want in the client, when I search for “ação” or “acao”, it should return this object.

The opposite I`ve alredy dont (filtering on client)

minimongo doesn’t have all features of mongodb. I think there are few options here.

  • You store both of 2 types of data (with and without “accentuation”) then you search for both of those fields
  • You send your search query to the server.

When you generate your data in DB you save both strings. I see a couple of cases:

  1. You only need to save names (of people, places etc) where in most cases the string is 1-2 words.
const transName = name.normalize('NFD').replace(/\p{Diacritic}/gu, '')
// trans is for transliterated (or normalized)

   name: 'String',
   transName: 'String'

  1. You have the ascii word as part of a longer text. In this case you can test the string for diacritics and if you have a word with diacritics, that you know you will want to search for you can just extract it/them (I mean copy, push to) into an array, in its transliterated form.

In both cases you do the search for the transliterated word. You normalize the search word before you query the DB and you search in the fields that contain the normalized version of the word.

Thanks for you answer. How can I do the second option? Sending search query to server?

You can just call a method with the search query as a param. On the server, you search and return the result.

Ok, I’ve been reading about indexes in Mongo and found this. Look for index collation.

" By specifying a collation strength of 1 or 2 , you can create a case-insensitive index. Index with a collation strength of 1 is both diacritic- and case-insensitive."