From Categories MySQL Table to MongoDB Design

I am coming from a MySQL background and I am trying to learn MongoDB. I have a product document and each product document has a category. Right now I am allowing the user to manually select a category, but I want to show a dropdown menu with all the categories that I have defined.

In MySQL, I would create a category table and pull all of them and show them to the user. How do I store these categories in MongoDB?


source to share

1 answer

In this case, I will still have a collection of categories and I have an ObjectId for another collection, just so you have a single master list of all categories, but you also have a built-in category in the document so you can search based on that. You won't have complete relationships, but you can track your category usage in one place.

IMO, mongo philosophy does not mean getting rid of all relationships, but simply having them where it makes sense.



All Articles