The best way to store multilingual data in MongoDB

mongodb

I want to save/serve multilingual data in my CMS application using Mongoose.

Is this the correct way?

name: {
    global: {
        type: String,
        default: '',
        trim: true,
        required: 'Please fill name',
    },
    en_US: String,
    tr_TR: String,
    sv_SE: String
}

Best Answer

I do not this that you have any "correct" or "bad" way, it is mostly based on your application design and requirements.

However, you may have noticed that in MongoDB 2.6.x the Full Text Search feature supports multi languages indexing and search if you specify a language in a document. This allow you to search text by language.

Documents look like:

{
_id: 1,
   language: "portuguese",
   original: "A sorte protege os audazes.",
   translation:
     [
        {
           language: "english",
           quote: "Fortune favors the bold."
        },
        {
           language: "spanish",
           quote: "La suerte protege a los audaces."
        }
    ]
}

for more informations:

http://docs.mongodb.org/manual/reference/text-search-languages/#text-search-languages

Related Topic