I’m building a personal shop app where users can sell items to each other, but I’m having a difficult time figuring out how to manage the products. For instance if you want to sell a t-shirt you should be able to pick a size and color etc. but if you sell a computer you should specify the year, cpu power etc. All products have a title, price, images and so on, but how would you get by with the varying attributes? I am using mongodb for the objects.
I was thinking about having a field attributes
which should be an object with the different details, and then a have field type
that would define which properties that exists. If type = 'Computer
then I would know that attributes
would look something like this.
attributes: {
capacity: 1000 // gb
ram: 4096 // MB
}
etc.
In a normal object oriented design I would have done this through inheritance / interfaces. If you have any idea on the best approach for this in mongoose / node.js I would be happy to hear about it.
If I'm not making myself clear in the question please tell me what is vague and what should be clarified
Edit:
The following article describes one solution to the problem http://learnmongodbthehardway.com/schema/chapter8/
It however doesn't state where to put the attributes. One solution might be to just store it in the category itself, but I'm not sure about best practices here though.