0
在dynamoDB中我有一個具有連字符屬性的表。 (例如名字)在DynamoDB中更新包含連字符或短劃線( - )的屬性
現在我想用javascript更新它們。 這是我到目前爲止的代碼:
//create UpdateExpression and ExpressionAttributeValues
let updateExpression = "set ";
let expressionAttributeValues ={};
if (e.firstName !== null){
updateExpression = updateExpression + " "+ 'first-name'+" = :f,";
expressionAttributeValues[":f"] = e.firstName;
}
let table = "tableName";
let bpNumber = e.bpNumber;
let params = {
TableName: table,
Key: {
"bpNumber": bpNumber
},
UpdateExpression: updateExpression,
ExpressionAttributeValues: expressionAttributeValues,
ReturnValues:"UPDATED_NEW"
};
console.log("Updating the item...");
docClient.update(params, function(err, data) {
if (err) {
console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2));
}
});
然而,這將引發我這個錯誤:
Unable to update item. Error JSON: {
"message": "Invalid UpdateExpression: Syntax error; token: \"-\", near: \"first-name\""
有沒有解決這個辦法嗎?
感謝您的幫助:)
真棒,這個工程。謝謝....我從來沒有在文檔中找到過 –