Dynamodb 更新失败并出现验证异常
Dynamodb updating fails with validation exception
您好,我在 dynamodb npm 中使用 Dynamodb,当我想更新我的仓库 table 中的数据时,我无缘无故收到以下错误?
它会更新我的数据,但突然因无意义的错误而崩溃。
有什么问题吗???
ValidationException: Invalid KeyConditionExpression: An expression attribute value used in expression is not defined; attribute value: :name
我的代码:
let updateData = {
customer: 'mrpen',
name: warehouseInfo.name,
street1: warehouseInfo.street1 ? warehouseInfo.street1 : 'N/A',
street2: warehouseInfo.street2 ? warehouseInfo.street2 : 'N/A',
city: warehouseInfo.city ? warehouseInfo.city : 'N/A',
state: warehouseInfo.state ? warehouseInfo.state : 'N/A',
country: warehouseInfo.country,
zip: warehouseInfo.zip ? warehouseInfo.zip : 'N/A',
contactName: warehouseInfo.contactName ? warehouseInfo.contactName : 'N/A',
contactEmail: warehouseInfo.contactEmail ? warehouseInfo.contactEmail : 'N/A',
contactPhone: warehouseInfo.contactPhone ? warehouseInfo.contactPhone : 'N/A',
inventoryName: data[0].attrs.inventoryName,
}
const res = Warehouse.update(updateData, (err, res) => {
if (err) {
throw new Error('update warehouse failed!');
} else {
console.log(res);
return true;
}
});
name
属性是 reserved words in DynamoDB 之一。您可以重命名该属性或定义一个表达式属性名称以用于代替保留字。
有关 expression attributes in the docs 的更多信息。
您好,我在 dynamodb npm 中使用 Dynamodb,当我想更新我的仓库 table 中的数据时,我无缘无故收到以下错误? 它会更新我的数据,但突然因无意义的错误而崩溃。 有什么问题吗???
ValidationException: Invalid KeyConditionExpression: An expression attribute value used in expression is not defined; attribute value: :name
我的代码:
let updateData = {
customer: 'mrpen',
name: warehouseInfo.name,
street1: warehouseInfo.street1 ? warehouseInfo.street1 : 'N/A',
street2: warehouseInfo.street2 ? warehouseInfo.street2 : 'N/A',
city: warehouseInfo.city ? warehouseInfo.city : 'N/A',
state: warehouseInfo.state ? warehouseInfo.state : 'N/A',
country: warehouseInfo.country,
zip: warehouseInfo.zip ? warehouseInfo.zip : 'N/A',
contactName: warehouseInfo.contactName ? warehouseInfo.contactName : 'N/A',
contactEmail: warehouseInfo.contactEmail ? warehouseInfo.contactEmail : 'N/A',
contactPhone: warehouseInfo.contactPhone ? warehouseInfo.contactPhone : 'N/A',
inventoryName: data[0].attrs.inventoryName,
}
const res = Warehouse.update(updateData, (err, res) => {
if (err) {
throw new Error('update warehouse failed!');
} else {
console.log(res);
return true;
}
});
name
属性是 reserved words in DynamoDB 之一。您可以重命名该属性或定义一个表达式属性名称以用于代替保留字。
有关 expression attributes in the docs 的更多信息。