userId as primary key in Dynamodb table even though it is not unique

Reference Chapter

In this chapter, we are creating a table in Dynamodb.

My question is that, here, we are using userId has the primary key.

However, in the aws dynamodb documentation, I read that the primary key has to be unique. Since the same user can create multiple notes, won’t there be multiple items with the same userId, and thus, how does using userId still work in this case when it is not unique?

Hi Callmekatootie,

In a table that has a partition (primary) key and a sort key, it’s possible for two items to have the same partition (primary) key value. However, those two items must have different sort key values.

This AWS document helps explain the concept: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html see the section Primary Key

Hope this helps,

Mke

2 Likes

Thanks much @mmaberry. The link you shared is very useful and cleared my doubt.

1 Like