Currently, I'm checking if the item exists with a query and then I'm using put or updateItem, I want to change it and make a single call to DDB. I want to make a query that will update or create item.
Here is a example of my item:
{
id: 'dsfadsf'
fa: { "apple" : { "S" : "76-100" }, "yolo" : { "S" : "0-25" }
pa: { "finish" : { "BOOL" : false }, "userKey" : { "S" : "3e299e12-9e66" } }
createdAt: 32432432423
}
item types:
createdAt - Number
fa - Map
pa - Map
id - String
finish - Boolean
key - String
If item exists I want to push a new item like {papa: 'dsfadsf'} (never modify existing item inside fa Map) and modify finish value inside pa Map
This is the item after the update:
{
id: 'dsfadsf'
fa: { "apple" : { "S" : "76-100" }, "yolo" : { "S" : "0-25" }, "papa": { "S" : "dsfadsf"} }
pa: { "finish" : { "BOOL" : true }, "userKey" : { "S" : "3e299e12-9e66" } }
createdAt: 32432432423
}
Here is what I tried and its not working
{
TableName: tableName,
Key: {
id: "dsfadsf",
},
UpdateExpression: `SET #id = :id, fa.${itemName} = if_not_exists(fa.${itemName}, :text), pa.finish = if_not_exists(pa.finish, :finishval), #ca = :ca`,
ExpressionAttributeNames: {
"#id": "id",
"#ca": createdAt
},
ExpressionAttributeValues: {
":id": "7fd9a81b-7a7c-4cfb-9c84-25dc2798a8f7",
":text": itemText,
":finishval": true,
":ca": 32432432423
},
ConditionExpression: `attribute_not_exists(id)`,
};