One-to-Many schema design

I am working on a schema design for a product store. There are two scenarios here:

  1. There will be about 100K products, most of them will have less than 10 parts, only 1 percent of the products will have more than 10 parts, the worst case is a product may have more than 4000 parts.

  2. There are total 100K products, 95 percent of them have less 20 parts, 5 percent have up to 50 parts.

Is there any good design pattern to implement this system with MongoDB?



Hi @mike_zenon ,

It sounds that most of the products can have the parts embedded in them as a few hundred of subdocuments is not a big deal.

It really comes down to the queries and the data presented by the application on each screen. Data that is queried together logically should be stored together.

Therefore I would go for the outlier pattern , mostly due to those products with the thousands of parts.

Those will probably need to hold top parts in the product but also split them into an outlier collection with a few chained documents. The total of parts can stored and updated in the main product document. This is how I would attack this.

Please read this