K
K
Konstantin2021-12-20 13:38:16
MongoDB
Konstantin, 2021-12-20 13:38:16

How to store a list of options in Mongodb?

I'm trying to decide how best to organize the storage of a list of product categories:

Дуб
Береза
Клен
и тд


Accordingly, a product may contain one or more categories.
I'm thinking of creating two separate collections (products and categories). And in the product document, have the field:

categories: [ObjectCategoryId, ObjectCategoryId, ObjectCategoryId]


where and refer to categories by key. But there is also a need for a count next to each category.

A product can have no more than 50 categories. Does it make sense to use an embedded strategy that will require all documents to be updated if the categories change?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question