0
votes

Is it possible to use multiple sort values in aws sdk dynamodb batchGetItem using one query? My aim is to be able to query the result of multiple sort keys? Or how is an efficient way of doing such a query?

E.g

Partition key / Sort key
A                  1
A                  2
B                  3

E.g input A and 1 and 2

1

1 Answers

0
votes

BatchGetItem requires you to specify the full primary key. That means you'd need to specify the partition key and the sort key at the same time.

For example, you could do the following (in pseudocode):

ddbclient.batchGetItem({

{
    "RequestItems": {
        "YOUR_TABLE_NAME": {
            "Keys": [
                {
                    "PK":{"S":"A"},
                    "SK":{"N": 1},
                },
                {
                    "PK":{"S":"A"},
                    "SK":{"N": 2},
                },
             ]
          }
      }
})

However, if you do not know the sort key and watch to fetch all the items with Partition Key = "A", you should use the query operation. The query operation does not require you to specify the sort key.

  dynamoDbLib.query({
    TableName: "YOUR_TABLE_NAME",
    KeyConditionExpression: "PK = A",
  });