当列表可能存在也可能不存在时,我正在尝试将条件放在列表的第一项上。我尝试先检查列表是否存在,但DynamoDB似乎没有缩短表达式。无论如何,我都会得到这个错误: ValidationException:提供的表达式引用了项目中不存在的属性。
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我似乎不能通过首先检查属性是否存在来使其短路。我还尝试使用if_not_exists()将checkIns替换为一个无意义的字符串,但得到了以下错误:
ValidationException:无效的ConditionExpression:条件表达式中不允许使用该函数;function: if_not_exists
有谁有什么想法吗?
发布于 2017-03-05 18:31:54
问题出在UpdateExpression而不是ConditionExpression。
以下更新修复了此问题:
params.UpdateExpression = 'SET #checkIns = list_append(:newCheckIn, if_not_exists(#checkIns, :empty_list))';https://stackoverflow.com/questions/42607143
复制相似问题