Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

best practice in mongo

 
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
 
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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic