D
D
DeniSidorenko2021-04-05 09:06:13
MongoDB
DeniSidorenko, 2021-04-05 09:06:13

What is the best way to implement data storage model in MongoDB?

Good afternoon, there is such a task. Implement food delivery from restaurants. As a result, I decided to make the following structure for the database

{
  "restaurant": {
    "name": "Restaurant 1",
    "products": [
      {
        "_id": ObjectId(),
        "name": "name1",
        "price": 850
      },
      {
        "_id": ObjectId(),
        "name": "name2",
        "price": 850
      }
    ]
  }
}


Thus, we receive only those products that relate specifically to this restaurant. And thus products do not exist as a model. But the question is, is this approach correct or should all products be put in the products collection and filtered when requested?

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