Answer the question
In order to leave comments, you need to log in
How to get all product categories from the database?
I have, for example, 10,000 different products, and they belong to 300 categories (electronics, food, toys...).
The question is, how in this case to properly fetch the list of categories in the mongodb database? I have an option to create a separate model for categories, and each time adding a new product, check whether there is such a category, and if not, then add it to the categories array. Here the load on the base, I think, will be minimal. There is another option, every time you need to get a list of products, make a selection based on all products (check categories in them). But here I do not really understand how to correctly describe it in the code. I will not take all the goods, then filter on the server and give to the client.
What is the best way to do such things?
Answer the question
In order to leave comments, you need to log in
so you can get all unique values
https://docs.mongodb.com/manual/reference/method/d...
create a separate model for categories, and each time adding a new product, check if there is such a category, and if not, then add it to the categories array
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question