I'm trying to put a condition on the first item on a list, when the list may or may not exist. I am trying to check if the list exists first, but DynamoDB doesn't seem to short circuit the expression. I get this error regardless: ValidationException: The provided expression refers to an attribute that does not exist in the item.
params.ExpressionAttributeNames = {
'#checkIns': 'checkIns'
};
params.ExpressionAttributeValues = {
':newCheckIn': [newDateString],
':justDatePart': justDatePart
};
params.UpdateExpression = 'SET #checkIns = list_append(:newCheckIn, #checkIns)';
// make sure task is not already checked in today
params.ConditionExpression =
'attribute_not_exists(#checkIns) OR (NOT begins_with(#checkIns[0], :justDatePart))';
return Table.updateAsync({ID}, params); // using dynogels-promisified
I can't seem get it to short circuit by checking whether the attribute exists first. Also I tried to use if_not_exists() to replace checkIns[0] with a meaningless string, but I get this error:
ValidationException: Invalid ConditionExpression: The function is not allowed in a condition expression; function: if_not_exists
Anyone have any ideas?