【发布时间】:2018-01-24 12:29:51
【问题描述】:
我正在尝试使用给定的分区键和排序键的范围查询 dynamodb 表,但 API 不断返回以下错误:
Amazon.DynamoDBv2.AmazonDynamoDBException KeyConditionExpressions 每个键只能包含一个条件
这是创建请求的 C# 代码:
var partitionKey = 10;
var from = DateTime.NowUtc.AddDays(-1);
var to = DateTime.NowUtc;
var queryRequest = new QueryRequest
{
TableName = _tableName,
IndexName = "index",
KeyConditionExpression = "#pkey = :v_pkey and #skey >= :v_from and #skey <= :v_to",
ExpressionAttributeNames = {
{"#pkey", "PartitionKey"},
{"#skey", "SortKey"}
},
ExpressionAttributeValues = {
{":v_pkey", new AttributeValue { N = partitionKey.ToString(CultureInfo.InvariantCulture) }},
{":v_from", new AttributeValue { N = new DateTimeOffset(from).ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture) }},
{":v_to", new AttributeValue { N = new DateTimeOffset(to).ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture) }}
},
ScanIndexForward = true
};
AmazonDynamoDBClient client = CreateClient();
var queryResponse = client.Query(queryRequest);
【问题讨论】:
标签: c# amazon-web-services amazon-dynamodb