![](/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.