Say I want to build a website that support multiple language and use MongoDB datastore. I wonder what is a good approach to have multiple versions of the body and title of an article, one for each language.
Should I keep all versions in the same article document? Like a collection of key-value pairs of language code and text in the body field of the article. This way I'd get no more than 1 request for viewing articles, but I'd also get more data than I might need so the response is larger.
Is there a better solution? How and why?
Best Answer
I use the following pattern for text that should be indexed in all the languages:
// now if want the text in English
// the use of objecttitle.languages index array it to improve performance in client accessing a determined text
// that allows us to add indexes to your translated texts on mongo, as
We can also wrap the code to obtain text in an specific language in a Class.