I have the following structure in DynamoDB:
{
"fruits": {
"1": {
"identifier": "orange",
"colour": "orange"
},
"2": {
"identifier": "strawberry",
"colour": "red"
}
},
"username": "my-username"
}
How do I add a '3rd fruit item' with its associated attributes? I am aiming to achieve the following:
{
"fruits": {
"1": {
"identifier": "orange",
"colour": "orange"
},
"2": {
"identifier": "strawberry",
"colour": "red"
},
"3": {
"identifier": "pear",
"colour": "green"
}
},
"username": "my-username"
}
I have tried something similar to the following:
result = table.update_item(
Key={
'username': str('my-username')
},
UpdateExpression='set fruits.3.identifier = :i, fruits.3.colour = :c',
ExpressionAttributeValues={
':i': 'pear',
':c': 'green'
}
)
Thank you!