D
D
DeniSidorenko2020-10-26 09:38:21
MongoDB
DeniSidorenko, 2020-10-26 09:38:21

What is the best way to implement such a connection?

Good afternoon, what is the best way to implement this connection. There is a model Product and a Category
For Category I set the fields Products (array) , (Types.ObjectId, rel="Category').
For Product I set the fields Category (not an array, because the choice of one category) . (Types.objectId, rel ='Product')

Logically, when adding a product, we select the desired category from the selection ( select ) in which all categories are listed. And then each product will have a category field in which the IDs of the desired category are located. But how to do that when adding the ID of this of the product fell into the array of the desired category.

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