Member-only story

ConditionalCheckFailedException: Update nested attributes in DynamoDb table — JavaScript SDK

Jorge Freitas
2 min readApr 29, 2021

--

Photo by Campaign Creators on Unsplash

Problem: Update query with nested attributed. I was receiving ConditionalCheckFailedException when the nested attribute was null.

After some research I figure out a workaround to be able to set nested attributes even if the root attribute is null.

Before

const updateParams: DocumentClient.UpdateItemInput = {
TableName: tableName,
Key: { keyName },
ConditionExpression: "#storeNumber = :storeNumber",
UpdateExpression: “SET #storeStatus.#status = :newStoreStatus, #storeStatus.#updatedOn = :newStatusUpdatedOn”,
ExpressionAttributeNames: {
"#storeNumber": "storeNumber",
"#storeStatus": "storeStatus",
"#status": "status",
"#updatedOn": "updatedOn",
},
ExpressionAttributeValues: {
":storeNumber": storeNumber,
":newStoreStatus": "online",
":newStatusUpdatedOn": "2021-04-29T13:29:00.9360188+00:00",
},
},
};

After

const updateParams: DocumentClient.UpdateItemInput = {
TableName: tableName,
Key: { keyName },
ConditionExpression: "#storeNumber = :storeNumber",
UpdateExpression: "SET #storeStatus = :newStoreStatus",
ReturnValues: "UPDATED_NEW",
ExpressionAttributeNames: {
"#storeNumber": "storeNumber",
"#storeStatus": "storeStatus",
}…

--

--

No responses yet