Below is a sample item object/record stored in DynamoDb. I use NodeJS and AWS.DynamoDB.DocumentClient to access the database.
I'm building out a PUT function to update the status for an JSON object in an array. The function will have access to the Item's uuid and room's uuid. How can I simply (creatively) update the value of corresponding status field, given the array of JSON objects?
Params:
let params = {
TableName: room-table,
Key: {
uuid: event.body.uuid
},
UpdateExpression : "??",
ExpressionAttributeNames: {
"??":"??"
},
ExpressionAttributeValues:{
"??":"??"
},
ReturnValues:"ALL_NEW"
};
Item Object:
{
"Item": {
"uuid": "77b1e88e-5e60-44d9-b6ca-aec345c0dc99",
"rooms": [
{
"room": "303",
"status": "pending",
"uuid": "b8f1c1a8-04a9-4c2e-82ad-bc3e81face35"
},
{
"room": "302",
"status": "pending",
"uuid": "42fdc61a-4a25-4316-90c9-60209875d208"
},
{
"room": "678",
"status": "pending",
"uuid": "7bedc115-20ed-4c3e-9cd7-7fed0520f4df"
}
],
"status": "pending"
}
}
Item.roomsarray for you. The only way to make it possible would be for you to changeItem.roomsfrom an array to an object where each key is a room's uuid. Then you could use an update expression of something likeSET rooms.#roomUUID.status = :roomStatus.