Design Question for multiple relationships

Hello,

I am more familiar with Relational databases and have a design question for a set of Collections.

I am working on a database that has Event Types, Categories, Sub Categories and Products.

For each Event Type, Category and SubCategory there can be many Products listed under each combination.

Do I just need to create one more collection that references one Event Type, Category, and SubCategory with multiple products?

The idea is that on a site a customer would select the event type, category and subCategory and a list of products will show up.

The example is a Wedding is the Event Type, Reception is the Category and Goblet is the SubCategory. I would get a list of goblets as the products.

Thank you in advance

1 Like

you can do this in many ways.
when it comes to Mongo DB you can Embed any level of Sub Documents.
if your sub document contain many fields then better to use reference collection. SpringData support with annotation @Dbref, as below data model.

if your sub document is simple just to do categorise just product_collection should work for you.

var product_collection = {
    Id: UUID(),
    name: "name of the product",
    event: "WEDDING",
    category: "RECEPTION",
    sub_category: "GOBLET"
}

var event_collection = [{
    Id: "WEDDING",
    name: "name",
    description: "Wedding Event"
}]
var category_collection = [{
    Id: "RECEPTION",
    name: "name",
    description: "description"
}]
var sub_category_collection = [{
    Id: "GOBLET",
    name: "name",
    description: "sub_category"
}]

when you come from RDBMS to NoSQL this is some thing we need to consider how it is consumed.