I am trying to model my objects on MonogoDB and not sure how to proceed. I am building a Product catalog that will be:
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?
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 :)
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.
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.
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.
MongoDB offers many advantages over traditional relational databases: Full cloud-based developer data platform. Flexible document schemas. Widely supported and code-native data access.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With