Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multilingual data modeling on MongoDB

I am trying to model my objects on MonogoDB and not sure how to proceed. I am building a Product catalog that will be:

  • No frequent changes to product catalog. A bulk operation may be done weekly / fortnight.
  • Product information is in multiple languages ( English, Spanish , French ) new language may be added anytime.

Here is what I am trying to do: I need to model my product catalog to capture the multilingual functionality. Assume I have:

product : {   _id:xxx,  sku:"23456",  name:"Name",  description: "Product details",   tags:["x1","x2"]}...  } 

Surely, name,description, tags and possible images will change according to language. So, how do I model it?

  1. I can have a seperate collection for each language eg: enProducts,esProducts etc
  2. Have JSON representation in the product itself with the individual languages like:

    product :{    id: xxx,    en: {          name: "Name",          description: "product details.."        },    es: {          name: "Name",          description: "product details.."        },    ...    } 


Or is there any other solution? Need help of MongoDB modeling experts here :)

like image 239
Abdel Raoof Olakara Avatar asked May 22 '14 09:05

Abdel Raoof Olakara


People also ask

What are the data modeling concepts used in MongoDB?

MongoDB provides two types of data models: — Embedded data model and Normalized data model. Based on the requirement, you can use either of the models while preparing your document.

Can MongoDB model many to many?

A Many-to-Many relationship (N:M) As there is no single command to implement a many-to-many relationship in a relational database, it is more difficult than a one-to-many relationship. The same is true when using mongoDB to implement them. In fact, you can't use a command to create any type of relationship in MongoDB.

Is MongoDB good for time series data?

From the very beginning, developers have been using MongoDB to store time-series data. MongoDB can be an extremely efficient engine for storing and processing time-series data, but you'd have to know how to correctly model it to have a performant solution, but that wasn't as straightforward as it could have been.

What is MongoDB competitive advantage?

MongoDB offers many advantages over traditional relational databases: Full cloud-based developer data platform. Flexible document schemas. Widely supported and code-native data access.


2 Answers

What about this approach:

product: {   id: 1,   name: 'Original Name',   description: 'Original Description',   price: 33,   date: '2019-03-13',   translations: {     es: {       name: 'Nombre Original',       description: 'Descripción Original',     }   } } 

If the user selects some language different to the default and the key translations exists in the object, you only need to merge it, and if any key has no translation, the original remains.

Another advantage is if you need to remove the translation feature or add/remove some language, you only need to change or remove the translation key and not having to refactor the entire schema.

like image 81
Damsorian Avatar answered Oct 04 '22 08:10

Damsorian


Another option would be to just keep the values different per language. Would probably make maintaining the schema much easier as well:

product : {   _id:xxx,  sku: {    und: "23456"  },  name: {    en: "Fork",    de: "Gabel"  },  description: {    en: "A metal thingy with four spikes",    de: "Eine Dinge aus metal der vier spitze hat"  }   } 

und would be short for "undefined", i.e. the same for all languages, and could be used as a fallback - or you always use "en" as fallback if you'd prefer that.

The above example is roughly how Drupal CMS manages languages (albeit translated from SQL to Mongo).

like image 22
Adam Gerthel Avatar answered Oct 04 '22 08:10

Adam Gerthel