Multi Collation in MongoDB

Viewed 793

Lets assume there is a collection called "Test" with a column "Name" that I restore names in 3 different languages (ja, th, ru).

What is the best way to declare 3 Collations on Name column in MongoDB which supports all 3 languages? Is it better to create Collation(s) on the Collection or Index? How to implement it?

I know that it is possible to declare simple as locale but this is not the best choice when it comes to comparison. If I don't want to use simple as locale how can I declare multi Collation for the collection/index/... to support all 3 languages?

1 Answers

I am researching collations in mongo right now so I may not have all the information but basically if you want your queries on strings to work in different languages you can pass collation as a parameter to a query:

db.Docs.find({ Name: "My Name"}).collation( { locale: 'en', strength: 2 } )

So you can specify different locale every time. You can also create an index with specific locale, this would be just needed for performance reasons. Mongo would find an appropriate index that matches locale of your query. However, since you may have many languages in your db, you would need to create an individual index for every language/locale and creating to many indexes is generally not ideal. Take a look at mongo documentation they have details.

Related