Sunny
Sunny

Reputation: 928

Referential Integrity management in aws dynamodb

I am trying to save category data in my aws dynamodb table.

Id | category |   difficultyLevels

1  | History  |  ['Easy', 'Medium']

Now the issue with this is the string 'Easy' and 'Medium' are hardcoded and tomorrow If i want to change the string 'Easy' to 'easy'. That would be very painful. So I am thinking to implement my tables as below:-

Table - DifficultyLevel

id    | Difficulty_Level

1     | Easy

2     | Medium

Table - Category

Id | category | difficultyLevels

1  | History  |  [1, 2]

Here the category table is saving the Difficulty level ids rather than the actual value. I am new to the world of NoSQL. So can you tell me if my approach is correct? or is there any other better option

The issue that I even see with this approach is that even if the difficulty levels 'Easy' is deleted from the DifficultyLevel table. Its reference is present in the Category table. Which is something we can control in a RDBMS.

Upvotes: 1

Views: 1310

Answers (1)

Mr Khan
Mr Khan

Reputation: 119

There is no referential integrity in NoSQL databases like Mongo. To achieve the above requirement you can use reference between documents where DifficultyLevel collection's document reference will be used in the category collection. Please look into Mongo docs for more details-https://docs.mongodb.com/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/index.html

Upvotes: 1

Related Questions