D
D
DeniSidorenko2021-03-30 06:59:09
Node.js
DeniSidorenko, 2021-03-30 06:59:09

How to create such structure in Mongo and add new data?

Good afternoon, there is such a task. Website of restaurants, each restaurant has data about itself and a field with products in the form of an array. When creating a restaurant, this field is an empty array, but when adding a product, a restaurant is selected for adding products.
The question is how to implement it correctly, each time to do PUSH in the array of products? And is it possible? I know that the field can be changed, do Update, but is it possible to add?
Of course, for example, you can get an array of products, put it in a variable, add a new product to that change and retransmit the updated array as a new value, but as for me, this is an extra operation. Is it possible to just PUSH?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Khokhlov, 2021-03-30
@andrhohlov

https://docs.mongodb.com/manual/reference/operator...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question