DynamoDB updating duplicated data

0

Hey there i am new in dynamoDB i have read the articles as well as blog but all these talk about quering the data, access pattern.The major issue i am facing is updating the duplicate data let just say i create a user in dynamoDB with PK = USER-1234 and SK= USER-1234 so if i want to get user i can simply get user by its PK i.e USER-1234. let just say if user create a review so i am saving it like PK = USER-123 and SK = REVIEW-3456 . the review column contains some user info like userName dateOfBirth like this.

PKSKuserNamedateOfBithReviewerNamereviewerDatOfBirth
USER-123USER-123tempname09-09-2022
USER-123REVIEW-45tempname09-09-2022

if userName is updated then we have to update the userName all across where data has been duplicated. let just say if user create 1000 reviews then i have to update userName across all entities.

asked 9 months ago262 views
2 Answers
1

You wouldn't store the personal user data in reviews, it doesn't make sense to do that.

PKSKuserNamedateOfBithReviewerNamereviewerDatOfBirthreviewDate
USER-123USER-123tempname09-09-2022
USER-123REVIEW-452023-01-01

Now you have 1 item containing user's information. If you want all reviews and user information in a single request, do this:

SELECT * FROM mytable WHERE PK = 'USER-123'

If you want only reviews:

SELECT * FROM mytable WHERE PK = 'USER-123' AND SK begins_with('REVIEW')

And if you want only the user info:

SELECT * FROM mytable WHERE PK = 'USER-123' AND SK = 'USER-123'
profile pictureAWS
EXPERT
answered 9 months ago
profile picture
EXPERT
reviewed 9 months ago
0

So according to you i dont need to store user info in reviews enitity. but how i am going to know who had created this review. let's just say user created a post and other users review on that post and i want to get all post reviews. by providing post id i can retrive all reviews but how do i know who had review on this post

|PK | SK | userName | profileImage | reviewDate |review| postDate | postDescription | reviewerId | | --- | --- | --- | --- | --- | --- | |USER-123 | dummyName |https://example.com | | | | | | |USER-123 |POST-123 | | | | | 2020/09/09| good day| | |USER-444 | dummyName2 |https://example.com | | | | | | | |USER-555 | dummyName3 |https://example.com | | | | | | | |POST-123 |REVIEW-23 | | |2021/09/09 |hello world | USER-444 | | | |POST-123 |REVIEW-44 | | |2021/09/09 |hello world | USER-555 | | |

So accroding to above example a user can create post and other user make reviews on it. USER-123 make a post with id POST-123 and other users review the post. if i want get all post reviews i can simple provide post key to all all post like

SELECT * FROM mytable WHERE PK = 'POST-123' AND SK begins_with('REVIEW')

by this command i can have all reviews but the question is who would i know user info who had make this reviews. According to you i dont have to store user info on reviews.

answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions