DynamoDb全球索引查询日期范围键

时间:2018-09-02 12:14:32

标签: amazon-dynamodb

我的代码与以下代码不匹配:

        var queryRequest = new QueryRequest
        {
            TableName = table,
            IndexName = "CreatedBy-Created-index",
            KeyConditionExpression = "CreatedBy = :createdBy",
            ExpressionAttributeValues = new Dictionary<string, AttributeValue>
            {
                {":createdBy", new AttributeValue {S = filterTasksRequest.CreatedBy.ToLowerInvariant()}}
            }
        };
        if (filterTasksRequest.OnlyShowRecent)
        {
            var earliestDate =
                new DateTimeOffset(DateTime.UtcNow.AddDays(-10)).ToUnixTimeSeconds()
                    .ToString(CultureInfo.InvariantCulture);
            queryRequest.ExpressionAttributeValues[":fromDate"] = new AttributeValue
            {
                N = earliestDate
            };
            queryRequest.KeyConditionExpression +=
                $" AND Created > :fromDate";
        }

错误是

  

一个或多个参数值无效:条件参数类型   与架构类型不匹配--->   Amazon.DynamoDBv2.AmazonDynamoDBException:一个或多个参数   值无效:条件参数类型与架构不匹配   输入

在排序键上没有日期过滤器就可以了

1 个答案:

答案 0 :(得分:0)

结果是我用排序键Created作为字符串而不是数字创建了索引。