![](/img/trans.png)
[英]How to get the item from dynamo db if its not primary or sort_key
[英]How to get the item in the dynamo db which match particular key
user
作为partition_key
,时间作为sort_key
user=abc@gmail.com
和message=192.168.1.1
使用过滤器Attr
,我可以用键和值提取
table.scan(FilterExpression=Attr("message").eq("192.168.1.1"))
现在如何为特定用户提取?
在 DynamoDB 中获取数据有两种主要方法; scan
query
当分区键已知时, query
操作可用于获取项目。 scan
操作通过搜索整个数据库返回一个或多个项目。 正如您可能猜到的那样, query
操作优于scan
操作,因为它是一种性能更高的操作。
在您的示例中,分区键是已知的。 因此,您应该使用query
操作来获取您想要的数据。 操作应该是这样的
table.query( {
"TableName": "YOUR TABLE NAME HERE",
"KeyConditionExpression": "#user = :user",
"FilterExpression": "#message = :message",
"ExpressionAttributeNames": {"#user":"user","#message":"message"},
"ExpressionAttributeValues": {":user": {"S":"abc@gmail.com"},":message": {"S":"192.168.1.1"}}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.