Dynamodb use multiple GSIs in a single query to achieve pagination

Viewed 112

I have the following dynamodb attributes:

  1. chatId (hash key)
  2. senderId (GSI-1 hash key)
  3. receiverId (GSI-2 hash key)
  4. timestamp (sort key, gsiSortkey)

The GSI on senderId will give all messages sent by me and the GSI on receiverId will give all messages sent to me.

However, if I need the list of all messages sent by me and send to me in a single query, I need to have both the senderId and receiverId in my query.

  1. Is there alternative way to achieve this behaviour without running two separate queries ?
  2. I need to paginate the results. So only if i get the result in a single query, I’ll be able to paginate using dynamodb’s nextToken
  3. If I query on chatId field and then apply filter expression on senderId and receiverId, pagination doesn’t return the desired count. Dynamodb performs the query and then runs the filter.
0 Answers
Related