当您的行同时使用哈希键和范围键时,有没有办法从 DynamoDB 中获取使用特定哈希键的所有行?
例子:
Hash Range
A B
A C
A D
E F
然后 getItems(Hash=A) 返回 3 行
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));
}
});
Run Code Online (Sandbox Code Playgroud)