我有一个叫银行结单的dynamoDB表。
它有一个主分区键:-
它有一个指数:-
StatementType-index
在StatementType列中有几条标记为"RBS“的记录
我是用C#写的:
public async Task<string> GetRecordList()
{
try
{
var request = new QueryRequest
{
TableName = "Bank-Statements",
KeyConditionExpression = "StatementType = :searchKey",
ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
{":searchKey", new AttributeValue { S = "RBS" }}}
};
var response = await dynamoDbClient.QueryAsync(request); //Error occurs here
foreach (Dictionary<string, AttributeValue> item in response.Items)
{
//do something with item
}
}
catch (Exception e)
{
logger.Info("Failed while Getting Record List");
logger.Info("Error: " + e.Message);
}
return "DONE";
}我得到了一个错误“查询条件丢失了关键模式元素: TransactionID”
当我使用StatementType索引作为关键时,我为什么要这样做呢?
发布于 2019-12-20 17:25:26
在另一个教程中,我发现了以下设置:
IndexName = "StatementType-index“。
此代码适用于:
public async Task<string> GetRecordList()
{
try
{
var request = new QueryRequest
{
TableName = "Bank-Statements",
IndexName = "StatementType-index",
KeyConditionExpression = "StatementType = :searchKey",
ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
{":searchKey", new AttributeValue { S = "RBS" }}}
};
var response = await dynamoDbClient.QueryAsync(request); //Error occurs here
foreach (Dictionary<string, AttributeValue> item in response.Items)
{
//do something with item
}
}
catch (Exception e)
{
logger.Info("Failed while Getting Record List");
logger.Info("Error: " + e.Message);
}
return "DONE";
}https://stackoverflow.com/questions/59428599
复制相似问题