user3751975
user3751975

Reputation: 21

How to query range key programmatically in DynamoDB

How to query range key programmatically in DynamoDB, I am using .Net AWSSDK ,I am able to query on Hash key with below code :

GetItemRequest request = new GetItemRequest
            {
                TableName = tableName
            };
            request.Key = new Dictionary<string,AttributeValue>();

            request.Key.Add("ID",new AttributeValue { S = PKValue });
            GetItemResponse response = client.GetItem(request);

Please suggest, Thanks in advance.

Upvotes: 2

Views: 884

Answers (1)

Erben Mo
Erben Mo

Reputation: 3634

There are two kinds of primary key in DynamoDB: Hash-only or Hash-Range. In the above code I guess your table is Hash-only and you use the hash key to retrieve an element with hashkey equals to PKValue.

If your table is in H-R schema and you want to retrieve a specific element with a hashKey and rangeKey, you can reuse the above code and in addition, add the {"RangeKey", new AttributeValue } into your your request.KEY

On the other hand, query means a different thing in DynamoDB. Query will return you a list of rows sorted in some order.

Upvotes: 1

Related Questions