I have a non-relational database in MongoDB where I store items with the following structure:
{
"_id": "64586748c079e955385c18af",
"operator": "KILIN",
"department": "EXAMPLE-DEPARMENT",
"city": "MIAMI",
"locality": "Usaquén",
"neighborhood": "LISBOA",
"start_date": "2023-04-29",
"final_date": "2023-04-29",
"reason": "programed",
"description": "AV 88 # 8123",
"status": "not_validated",
"customers_affected": [
{"ENEL-BOG-00013":{"name": "tecniglas", "Phone": 3456752}},
{"ENEL-BOG-00111":{"name": "pepsi", "Phone": 2354321}},
]
}
The database deals with many service outage alerts. My question is focused on the "customers_affected" element. There are a number of customers in the country, and each alert can affect them depending on their location. I will constantly have to be querying the customers for each alert to send notifications (either by sms or email). My doubt is if I should leave it as I have it structured or if I should save in another collection all the clients and link them somehow with the alerts.
List out your pros & cons e.g. (nb: I'm not claiming this is exhaustive)
Option 1: Keep customer data within the same document
Pros:
Cons:
Option 2: Store customer data in a separate collection and link it with the alerts
Pros:
Cons:
It's up to you to decide which option best suits your use case. If you have a relatively small number of customers and don't expect frequent updates, keeping the customer data within the same document might be a simpler and more efficient approach. If however you expect a large number of customers and frequent updates, storing customer data in a separate collection and linking it with the alerts might be a better choice for performance and maintainability. And: as you will constantly have to be querying the customers for each alert to send notifications, it may be better to store the customers in a separate collection and link them to the alerts using a unique identifier.
NB: This is response is "generic", without much information on volumes or predicted growth and without any ability to perform any tests.