I have the following data structure with multi-level Map columns/items:
{
"pk": {
"S": "cf633075-e808-4e33-9fc1-08301b54384b"
},
"active": {
"N": "1"
},
"delta": {
"N": "-0.9371997798455771"
},
"dte": {
"N": "0.01893752246685426"
},
"hedge_positions": {
"M": {
"151e9c9f-aa5d-4f5d-9826-74011da03137": {
"M": {
"active": {
"N": "1"
}
}
},
"1bed59c9-6f73-48ae-8b65-62fd1f10ddad": {
"M": {
"active": {
"N": "1"
}
}
},
"24cf6015-780e-408d-b0e1-935ae2c7199d": {
"M": {
"active": {
"N": "1" //Update this to 0
}
}
}
}
}
I now wish to update the value of "active" for one of the "hedge_positions" to 0. The hedge_positions is a Map, containing unique Maps.
In Javascript, I have built the following update, but I am recieving the error "The provided expression refers to an attribute that does not exist in the item".
const AWS = require('aws-sdk');
const dynamoDb = new AWS.DynamoDB({region: process.env.AWS_REGION});
var hID = "24cf6015-780e-408d-b0e1-935ae2c7199d";
var params = {
TableName: Positions,
Key: {
pk: {"S": positionId }
},
UpdateExpression: "SET #hp.#id.#a = :a",
ExpressionAttributeValues: {":a": {"N": "0"}},
ExpressionAttributeNames: {"#hp": "hedge_positions", "#id": hID, "#a": "active"}
};
await dynamoDb.updateItem(params).promise();
I believe this to be because I am not specifying that the "GUID" is a Map. I have tried to set the UpdateExpression to "SET #hp.#id.M.#a = :a" but to no avail. What have I set incorrectly in the UpdateExpression?