2

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 Answer 1

2

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",
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.