I have the following dynamodb attributes:
- chatId (hash key)
- senderId (GSI-1 hash key)
- receiverId (GSI-2 hash key)
- 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.
- Is there alternative way to achieve this behaviour without running two separate queries ?
- 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
- 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.