Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

best practice in mongo

 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have Ingredient and Product collection. To manufacture a Product, multiple Ingredients is needed and one Ingredient may be needed for the manufacturing process of multiple Product. in mysql, I'd have 3 tables: product, ingredient, manufacture header and manufacture detail. manufacture header will have manufacture description such as name, date, plant id, etc and detail will have the product id and ingredient id. how to achieve this is mongo DB? denormalized? thanks
 
arumugarani sundaram
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

mongo is a document data store. So, I think as far as ingredient and product tables are considered, you can have it as separate collection in mongo. If we come to manufacture part, we can club both the tables into a single collection manufacture where manufacture detail will be an array element of nested structure

So, ideally the manufacture collection will look like

{

manufacure_id:1,
manufacture_name:"sample",
manufacutre_plant:"test",
...
manufacture_details:
[
{
ingredient_id:1,
product_id:111
},
{
ingredient_id:2,
product_id:111
},
{
ingredient_id:3,
product_id:111
},
{
ingredient_id:1,
product_id:112
},
{
ingredient_id:5,
product_id:112
},
{
ingredient_id:3,
product_id:112
}
]
}

Hope it helps.

Thanks,
Arumugarani
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic