Help modeling my product DB

Hi there,

I’m a newbie to MongoDB and could use some help with my db.

I want to build a db that stores product data. A product has a lot of attributes that I want to embed in the product itself. Additionally a product can be purchased in 1-n markets and is assigned to 1 category.

In the app the user has a category list and once he selects a category all products of the category are listed in a grid. He also has the possibility to filter the products to see in which markets they’re available.

I watched some tutorials and I believe it’s best to have three collections (products, markets, categories), since there are cases in the app where I would query products, markets and categories independently.

In each category and each market I’d store the id’s of all assigned products in an array. In the product itself I’ll have an array with the related market id’s and an attribute with the category id.

Does this sound right to you or do you have any suggestions for improvement.

Any help is much appreciated.


Hi @tmmsdlczek,

Welcome to MongoDB community!

It sounds like a classic online store schema that you are looking for where products collection will probably be the main one. I would recommend keeping as minimum amount of collections as possible therefore embedding as much as possible into the product document sounds correct.

Of course data must be also logically segregated according to the application access patterns. I think a following document might be good fit:

ProductId: ....,
ProductName: ...,
Category: [ ... ],
Markets : [ { marketId: ... , MarketName : ...}...]

I assume there will still be catagories and market collections but you can still index category and markets fields to search products solely on products collection…

Also read the following blog


1 Like

Hello : )

I try to have the least collections possible,for simplicity and performance.
1)embeded documents/arrays ,with indexes
2)if query from many locations , separate and duplicate data
3)if many updates on duplicated data , references in arrays and joins

See this topic,the answer from Michael Höller
He gathered additional links that can help :slight_smile:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.