'Structure with more Depth vs more breadth in Mongodb overhead
I'm trying to store user notifications in mongoDB ( My main database is Mysql ) and the notification table has over 2,500,000 records for each notification.
I want to know that should i store each notification in one row or store them based on user_id, each row containing all notifications of an user. Queries that will perform on these data are selecting all notifications of a user and selecting all notification with notified flag set to false and updating a flag of a notification with notification id.
Each row on table has id,user_id,description,read,notified
Which one has less overhead?
Solution 1:[1]
Store each notification in one row would be recommended since query or update would be easier.
Good
_id:"1"
user_id: "1",
description: "123",
read: true
Only if notifications and fields are less each user.
_id:"1",
user_id: "1",
notifications: [
{
_id:"1",
description: "123",
read: true
}]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | YuTing |
