• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

best practice in mongo

 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic