【问题标题】:query key condition not supported between c# AWS Dynomodbc# AWS Dynamodb 之间不支持查询键条件
【发布时间】:2018-06-29 13:15:34
【问题描述】:

我使用 QueryRequest 从 dynomoDb 获取结果,如果我单独发送 emp_id,它会返回结果。假设如果我再传递一个查询参数,它会返回

不支持查询键条件

请检查下面提到的代码,如果有任何错误,请告诉我。

 var _request = new QueryRequest
            {
                TableName = "Attendence",
                KeyConditionExpression = "Roster_EmpID = :Roster_EmpID and Roster_CreatedDateTime between :v_start and :v_end",
                ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
                    {":Roster_EmpID", new AttributeValue {  S = result.empId    }}
                    ,{":v_start", new AttributeValue {   S = result.fromDate.ToString(AWSSDKUtils.ISO8601DateFormat)  }}
                    ,{":v_end", new AttributeValue { S = result.toDate.ToString(AWSSDKUtils.ISO8601DateFormat)    }}
                },
                IndexName = "Roster_EmpID-index"
            };

即使我正在传递 aws 日期格式 (AWSSDKUtils.ISO8601DateFormat),也很难找到解决方案。请帮我找出问题。

【问题讨论】:

    标签: c# amazon-web-services amazon-dynamodb


    【解决方案1】:

    我们可以使用过滤器

                var _request = new QueryRequest
                {
                    TableName = "Attendence",
                    KeyConditionExpression = "Roster_EmpID = :Roster_EmpID",// and Roster_Date between :v_start and :v_end",
                    FilterExpression = "Roster_Date between :v_start and :v_end",
                    ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
                        {":Roster_EmpID", new AttributeValue {  S = result.empId    }}
                        ,{":v_start", new AttributeValue {   S = result.fromDate.ToString(AWSSDKUtils.ISO8601DateFormat)  }}
                       ,{":v_end", new AttributeValue { S = result.toDate.ToString(AWSSDKUtils.ISO8601DateFormat)    }}
                    },
                    IndexName = "Roster_EmpID-index"
                };
    

    否则需要使用添加排序键创建索引,并且需要使用该索引名称。

    Sample image

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 2017-04-01
      • 1970-01-01
      相关资源
      最近更新 更多