user
as partition_key
and time as sort_key
user=abc@gmail.com
and message=192.168.1.1
Using filter Attr
, I can extract with key and value
table.scan(FilterExpression=Attr("message").eq("192.168.1.1"))
Now how to extract for particular user?
There are two primary ways to fetch data in DynamoDB; scan
and query
The query
operation can be used to fetch an item(s) when the partition key is known. The scan
operation returns one or more items by searching the entire database. As you might guess, the query
operation is preferred over the scan
operation because it's a more performant operation.
In your example, the partition key is known. Therefore, you should be using the query
operation to fetch the data you are after. The operation should look something like this
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"}}
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.