Bill of material data modelling

Hello

I want to build data model for storing versioned Bill of material.

I have parts collection which stores all documents of parts like screw , nut, bolt, break pad, lever etc…

Now I want to store the versioned BOM for a product.

using the parts i need to create a product
Lets create a product Cycle - https://www.researchgate.net/figure/Bicycle-bill-of-material-BOM-structure_fig1_268206480

Cycle can also have diff variants eg, Electric cycle or Model X variant of a cycle which will change the hierrachy. which also be needs to store.

I need to answer queries like
Get tree hierarchy for eg. Brake or Complete Cycle at basic.

Hi @grizzly_monkey ,

Welcome to MongoDB community.

Design questions are tricky as the best design is taking your specific application needs and queries and using the advantages of complex document objects while avoiding the known antipatterns.

So this discussion might need several iteration and further testing to align with that.

Having said that, if the products have versions as a whole meaning that each version have a static version of all parts it make sense to have a parent document to a product embedding all ids of specific parts version:

{ _id : ...,
 ProductName : "bicycle"
 Version : "xxx",
 Level1Parts : [ { partId : objectId , version : 5, partName: ... } ... ],
Level2Parts : [ { partId : objectId , version : 1, partName : ... } ... ]

Now extended the parts data might live in parts collection :

{
_id : ...,
partName : "pedal",
Version : 123,
Created: "2021-01-01"
...
}

Each search criteria should be indexed to optimise performance.

The amount of data you embed and how you seperate should be done based on application query needs, best practices and avoiding antipatterns. Suggest to read:

Let me know your concern and thoughts.

Thanks
Pavel