C# dynamodb 错误:查询条件缺少键架构元素:主键
Posted
技术标签:
【中文标题】C# dynamodb 错误:查询条件缺少键架构元素:主键【英文标题】:C# dynamodb Error: Query condition missed key schema element: primary key 【发布时间】:2017-11-23 12:49:55 【问题描述】:每当我尝试使用 C# 文档模型查询 dynamodb 表时,都会引发异常
do
var request = new QueryRequest
TableName = "oauth_users",
KeyConditionExpression = "user_id = :user_id",
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
":user_id", new AttributeValue S = userid_str ,
// Optional parameters.
Limit = 1,
ExclusiveStartKey = lastKeyEvaluated
;
var response = client.Query(request);
// Process the query result.
foreach (Dictionary<string, AttributeValue> item in response.Items)
lastKeyEvaluated = response.LastEvaluatedKey;
while (lastKeyEvaluated != null && lastKeyEvaluated.Count != 0);
错误:
查询条件遗漏键架构元素:主键
如何使用不是主键而是全局二级索引的 dynamodb 键进行查询?
【问题讨论】:
【参考方案1】:答案是我们必须指定我们试图在查询中使用的全局二级索引的相应索引名称。例如:在请求中包含 IndexName 参数,这是查询全局二级索引列的强制键。
do
var request = new QueryRequest
TableName = "oauth_users",
KeyConditionExpression = "user_id = :user_id",
ExpressionAttributeValues = new Dictionary<string, AttributeValue> ":user_id", new AttributeValue S = userid_str ,
IndexName = "useridindex",
// Optional parameters.
Limit = 1,
ExclusiveStartKey = lastKeyEvaluated
;
var response = client.Query(request);
// Process the query result.
foreach (Dictionary<string, AttributeValue> item in response.Items)
lastKeyEvaluated = response.LastEvaluatedKey;
while (lastKeyEvaluated != null && lastKeyEvaluated.Count != 0);
希望它可以帮助某人,谢谢。祝你有美好的一天
【讨论】:
以上是关于C# dynamodb 错误:查询条件缺少键架构元素:主键的主要内容,如果未能解决你的问题,请参考以下文章
使用 Node 从 Lambda 查询 Dynamodb - 缺少键