Reputation: 5003
iam trying to update json array.i have a table in dynamoDb.i successfully inserted the json data to dynamo using put method.
Partition key : _id , Type : S
This is my json data saved into the database.
{
"_id": "001",
"email": "[email protected]",
"class": {
"student_list": []
}
}
But i cant updated json array student_list using key email. I have following code
var AWS = require("aws-sdk");
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName: "testTable1",
Key: {
"email": "[email protected]",
},
UpdateExpression: "set class.student_list = list_append (class.student_list, :studentEmail)",
ExpressionAttributeValues: {
":studentEmail": "[email protected]"
},
ReturnValues: "UPDATED_NEW"
};
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));
}
});
But i got an error message like this
Unable to update item. Error JSON: {
"message": "Invalid UpdateExpression: Incorrect operand type for operator or function; operator or function: list_append, operand type: S",
"code": "ValidationException",
"time": "2016-07-18T14:31:44.978Z",
"requestId": "378NSB5RVB1TNI0PB1Q3OH67V3VV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 0
}
What is the actual issue related with this?
Upvotes: 3
Views: 760
Reputation: 1273
From the docs: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html
Operand type must be contained in a list.
"The new element must be contained in a list, for example to add 2 to a list, the operand would be [2]"
Upvotes: 1