As the database specialist in a chocolate shop, you need to create a MongoDB collection to store information about chocolates(such as name, price, type) and chocolate producers (such as name, address). There are many producers; each of them produces many different chocolates, and new chocolates are frequently created. a. Describe what would be a good data model to store this data, justify your answer. [5 marks] b. Give a simple example of a portion of your collection in JSON format including example documents for two chocolates and one producer.
时间: 2023-12-10 18:41:07 浏览: 197
a. A good data model for this scenario would be to have two collections, one for chocolates and one for producers, linked by a common field such as producer ID. The chocolate collection would have fields such as name, price, type, and producer ID, while the producer collection would have fields such as name and address. This allows for efficient querying and updating of the data, as well as scalability as new chocolates and producers are added to the database.
b. Here is an example of a portion of the collection in JSON format:
Chocolates collection:
```
[
{
"name": "Dark Chocolate",
"price": 3.99,
"type": "Dark",
"producer_id": "1234"
},
{
"name": "Milk Chocolate",
"price": 2.99,
"type": "Milk",
"producer_id": "5678"
}
]
```
Producers collection:
```
[
{
"name": "Chocolate Co.",
"address": "123 Main St.",
"producer_id": "1234"
},
{
"name": "Choco Factory",
"address": "456 Elm St.",
"producer_id": "5678"
}
]
```
阅读全文