here is the image of data in dynamodb
我想要从favRest中删除元素,我只需要给出值,它应该这样做,这是我的lambda函数
var AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({ region: 'us-east-1' });
exports.handler = (event, context, callback) => {
const params = {
TableName : 'User',
Key:{
"id": event.user_id,
},
UpdateExpression: "DELETE favRest :p",
ExpressionAttributeValues: {
':p': event.place_id
},
ReturnValues: "ALL_NEW"
}
// TODO: Implementation...
docClient.update(params, (err, data) => {
if (err) {
console.log("Unable to update item. Error: " + err.message);
callback(err);
} else {
console.log("UpdateItem succeeded.");
callback(null, data);
}
});
};但是,它给出了以下错误:
"{\n \"message\": \"Invalid UpdateExpression: Incorrect operand type for operator or function; operator: DELETE, operand type: STRING\",\n \"code\": \"ValidationException\",\n \"time\": \"2018-04-29T18:49:58.628Z\",\n \"requestId\": \"7TDRI4TOF9S71OUJDEKMIOA40RVV4KQNSO5AEMVJF66Q9ASUAAJG\",\n \"statusCode\": 400,\n \"retryable\": false,\n \"retryDelay\": 35.34160854636804\n}"我应该做些什么?
发布于 2018-04-30 14:14:52
DELETE操作仅支持Set数据类型。您的favRest属性类型为List。
如果希望将favRest属性类型保留为List,则可以使用REMOVE从列表中删除单个元素(知道元素的索引):
UpdateExpression: "REMOVE favRest[:index]"或者,您可以使用SET将整个列表替换为新值:
UpdateExpression: "SET favRest = :newList"否则,您可以将favRest属性类型更改为Set。
https://stackoverflow.com/questions/50091522
复制相似问题