Home > Back-end >  Get data based on sort index AWS dynamoDB
Get data based on sort index AWS dynamoDB

Time:10-15

I have a DynamoDB table like this:enter image description here

I want to list all posts irrespective of users, i-e by getting all data whose sort key is "post". How can I achieve this?

I have heard about Global Secondary Index, but couldn't figure out how to use them.

CodePudding user response:

You create a global secondary index with a Key Schema like this:

  • Partition Key: SK attribute of the base table
  • Sort Key: PK attribute of the base table

It's called an inverted index. Then you can Query the Global Secondary Index by specifying the IndexName in the Query and search for all items that have "post" as the value for SK.

  • Related