Use of collation in mongodb $regex

后端 未结 2 740
無奈伤痛
無奈伤痛 2021-01-06 02:26

Since v3.4 collations are available for find operations, especially as matches for diacritic characters are concerned. While a find query with a definite value ($eq opeartor

相关标签:
2条回答
  • 2021-01-06 02:48

    There is no need to use collation on top of regex. You can functionally implement this behaviour using the correct regex.

    Considering to the Antwerpen example the following regex gives you all the matches in the database:

    /antw[eë]repen/i

    To generate the above regex you have to regex-replace your search string first using the following replace formula:

    str.replace(/e/ig, '[eë]')

    And of course you have to do it with all diactric character. Also you can simply use the following library: diacritic-regex.

    0 讨论(0)
  • 2021-01-06 03:08

    Documentation

    Case insensitive regular expression queries generally cannot use indexes effectively. The $regex implementation is not collation-aware and is unable to utilize case-insensitive indexes.

    0 讨论(0)
提交回复
热议问题