0
votes

Is there anyway to support more than 2 keys in a DynamoDB table? I have assessments that user fill and I need to index by user and assessment (several types of assessment each with different unique names). However, I also want to allow users to store different answers to each assessment (e.g. different dates or different contexts) My data structure for assessment answers is:

  • Sort key["S"]: IDUser (User ID from AWS Cognito that has answered)
  • Range key["S"]: IDAssessment (unique assessment name)
  • Answers["M"] in which the different answers to the assessment are stored
  • Additional key ["S"]: to differentiate between assessments by name or date

My data structure for assessments schemas (that define a schema) is:

  • Sort key["S"]: IDAssessment (unique assessment name)
  • Range key["S"]: IDUser (User ID from AWS Cognito that owns the assessment)
  • Additional key ["S"]: to classify the assessments by types and access them by type
  • Name["S"] of the assessment
  • Categories["M"] the map containing the assessment questions and levels

I think that requires at least three keys in Dynamo DB (user, assessment, answer-name) however it only allows me to create a sort and range key Is there any way to do it? Am I missing something? Thanks everyone

1
You can setup Secondary indexes, or you could create composite keys by combining attributes. Its really not clear what you are trying to achieve though. Why do you think you need 3 keys? Can you describe your data and schema in more detail?F_SO_K
Thanks Stu. Very useful. Have updated the structure on the question as requested. Thinking through the database structure I don't think I really need another key for the assessment answers as I can just store the data in different maps within the same item. For the Assessment Schema the secondary index is perfect to be able to select schemas by typejaimerr
OK, and what queries do you want to be able to do? Also, Sort Key and Range Key are the same thing, I think you need to change Sort Key for Partition Key in your question.F_SO_K
I will read up on partition keys. Extremely helpful. I am new to NoSQL and it takes a different way of thinking compared to traditional relational databasesjaimerr

1 Answers

0
votes

Yes, by creating a Secondary index for each of your additional columns and making your column the index sort key.