Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query List of Maps in DynamoDb

I have of the non-primary key column in DynamoDb which is of List type as this:

logs=[{
m1:{"key1":"pair1",
"key2":"pair2",
"timestamp":2189321.212
},
m2:{"key1":"pair1",
"key2":"pair2",
"timestamp":2112321.212
},
...
}]

So problem statement is I want to get a list of items, which are 30 days old. I am not able to query this one.

like image 267
Atul Kumar Avatar asked Oct 28 '25 08:10

Atul Kumar


2 Answers

It is not possible to do that directly using DynamoDB functions.

You could load and serialise each table log item into an object in your code, then sort and filter the objects. If you had a lot of log files this could use up a lot of memory.

If you are in control of how the log data is stored, you may want to remodel your tables, so that the logs are stored as table items. You could make log id your partition key and the timestamp a range key, which would make time based queries very fast.

If you went down that route, be aware that you would need to make your timestamp a number in DynamoDB in order to use it as a range key.

like image 136
F_SO_K Avatar answered Oct 30 '25 14:10

F_SO_K


Let me know if below is useful.

I had my data inserted like this through CLI:

enter image description here

This is how it would look once entered: enter image description here

And through Java code simply mapped it like this. This works. enter image description here

like image 27
Ajay Menon Avatar answered Oct 30 '25 14:10

Ajay Menon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!