I want to store a list of items beloging to some parent object.
Parent Object would be like following:
user_id - hash key
timestamp - range key
attributeA - String
attributeB - Number
listC - List of objects
listC is a list of objects (like JSON), where each object can have a few fields:
attrX - number
attrY - string
attrZ - string
The size of the list can be varied, from few elements to hundreads.
How should I store them?
Due to DynamoDB's limits, I'm afraid that I cannot keep this list as an attribute of parent object. I think to move these lists to another table. However, I'm not sure if should I:
Approach (1):
-------------------------------------
| parent_id | attrX | attrY | attrZ |
-------------------------------------
| 178 | 2 | "abc" | "xyz" |
-------------------------------------
| 178 | 2.4 | "klm" | "qwe" |
-------------------------------------
Approach (2):
------------------------------------------------------------------------
| parent_id | Chunk | ListC |
------------------------------------------------------------------------
| 178 | 1 | [{ X: "2", Y: "abc" }, { X: "2.4", Y: "klm" } ] |
-------------------------------------------------------------------------
| 178 | 2 | [{ X: "2.8", Y: "nop" }, { X: "3.2", Y: "qrs" } ] |
------------------------------------------------------------------------
What would you recommend me?
DynamoDBMapper can store List<CustomObject> but not Set<CustomObject> #331.
DynamoDB transactions DynamoDB transactional API operations have the following constraints: A transaction cannot contain more than 25 unique items. A transaction cannot contain more than 4 MB of data.
Choose Import CSV file. Select your CSV file and click Open. The data in the CSV file will be appended to your table. If your CSV file contains one or more rows that have the same keys as items already in your table, you will have the option of overwriting the existing items or appending them to the end of the table.
Actually, the approach depends on the Query Access Pattern (QAP).
Approach 1:-
Typical, normalized approach similar to RDBMS design. However, we need to think this on NoSQL perspective. There is no join in DynamoDB. Potentially, you may need to read two tables to get the required data. Please note that cost is calculated based on Read Capacity Units. So, the two different reads will cost you.
This approach may be acceptable if the item size exceeds the DynamoDB item size 400 KB
You can write query expression to filter the data by attributes attrX, attrY and attrZ as they are stored as normal scalar data type attributes
Approach 2:-
Preferred NoSQL approach to keep all the required data in one table. Join or additional read is not required
Need to consider whether the item size can exceed 400 KB
Whether you need to write query to filter the data by attributes attrX, attrY and attrZ. Please note that in this approach the ListC data is stored as List of Map DynamoDB data type. In most scenarios, DynamoDB doesn't have the flexibility to query the complex data structures like this (i.e. Map inside List data type)
List of Objects - means List of Map on DynamoDB database
{ X: "2.8", Y: "nop" } - is the object. This translates to MAP data type on DynamoDB database.
The outside square bracket translates to LIST data type on DynamoDB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With