I am creating an application to store bookmarks and every bookmark might have many labels. I am new to NoSQL databases and can't figure out how to structure my table. For now I have the following model:
PK SK data
USER#1 USER some data
USER#1 BOOKMARK#1 bookmarkDetails
USER#1 LABLE#1 labelDetails
LABEL#1 BOOKMARK#1 bookmarkDetails
With it I can query all user bookmarks and all user labels. But I need to store in the bookmark details which labels are assigned including title and color for example. But what happens when I want to update details of the label and change the name? Should I go through all bookmarks and update the title of the label where it exists? And in the case of DynamoDb that would mean I need to send many request to fetch the bookmarks that I need to update and then send update request.
Is it okay to store the labels that are assigned to a bookmark in bookmarkDetails and store the bookmarks that have the given label in labelDetails? This will lead to the need to update many rows if I change the title of the label or title of the bookmark. Coming from an RDS world this seems overwhelming and huge development effort. Is there another way to represent ManyToMany relationship? In this case I need to be able to fetch all bookmarks by label and that's why I am following this approach.
EDIT: I am adding the access patterns that I will need here to be more clear.
Entities:
User: ID and email
Bookmark: ID and url
Label: ID and title
Relations:
User to Bookmark = OneToMany
Bookmark to Label = ManyToMany
- Fetch all bookmarks by user ID - including details about all the labels that are attached to a given bookmark
- Fetch all labels by user ID
- Fetch all bookmarks by label ID - including information about all labels that are attached to the given bookmark
And the update actions are to be able to change the label title and bookmark url