Reputation: 713
Is there a way to get all rows from DynamoDB that use a specific hash key when your rows use both hash key and range key?
Example:
Hash Range
A B
A C
A D
E F
Then getItems(Hash=A) returns 3 rows
Upvotes: 4
Views: 6466
Reputation: 39166
Yes, it is possible using the Query API. Here is the sample code (Node JS).
I have a Movie
table with hash key (year key) and sort key (title). I have queried using the hash key. I have got four items in the result i.e. four titles available for the year 1992.
var docClient = new AWS.DynamoDB.DocumentClient();
var table = "Movies";
var year_val = 1992;
var params = {
TableName : table,
KeyConditionExpression : 'yearkey = :hkey',
ExpressionAttributeValues : {
':hkey' : year_val
}
};
docClient.query(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err,
null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
Upvotes: 6