Mapping dilemma

I need to come up with a proper data model for the following scenario:

We are building an application on which users can search for categories, stores and products.

1 Store can have multiple Products, 1 Product belongs to only 1 Store
1 Category can have multiple Products, 1 Product can belong to multiple Categories

Originally I wanted to implement Parent/Child relationships as such:
"store": "product"
"category": "product"
I realize now that this is obviously not possible since a Product can not have more than one parent.

I am thinking now of keeping that Parent/child relation between Stores and Products, and handle categorization with nested Category objects within the Product objects.
I'm wondering if this would be the ideal approach to this? I must also say that Products will be updated on a daily basis or even more frequently, and categories will be added or removed from products regularly as well, if that has any effect on which approach I should take for this problem?

Have you considered flattening it completely? As store seems to be updated infrequently or not at all, this could be denormalised onto the product records, and the product would then also simply have a list of categories.

Would this match how you want to query and aggregate over your data?

Hi Christian and thank you for your interest in this.

This is also a solution that I consider since stores are indeed very rarely updated.
With this approach of nesting everything within the Product documents, is it going to be easy to query for:

  • All available stores, or a specific store
  • All available categories, or a specific category
  • A product count for each store/category

Many thanks

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