I'm trying to update my DynamoDB table using a conditional write, after read the official doc (https://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.NodeJs.03.html#GettingStarted.NodeJs.03.05) I'm getting an error, I think this is a Syntax error, but I'm not sure, this is my code:
dynamodb.updateItem({
dynamodb.updateItem({
"TableName": "MyFavTable",
"Key":{
"MyFavKey": {
"S": "MyFavKey"
}
},
"UpdateExpression": "set MyLovelyBool=false",
"ConditionExpression": "MyLovelyBool == :p",
"ExpressionAttributeValues":{
":p":true
}
}, 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));
}
});
This run 'fine' by I get this error:
Unable to update item. Error JSON: {
"message": "Expected params.ExpressionAttributeValues[':p'] to be a structure",
"code": "InvalidParameterType",
"time": "2016-10-22T14:48:42.961Z"
}
I check if the json is valid and I was reading about ExpressionAttributeValues here (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html#ExpressionAttributeNames) but I don't get info to resolve my problem.
Expression attribute values in Amazon DynamoDB are substitutes for the actual values that you want to compare—values that you might not know until runtime. An expression attribute value must begin with a colon ( : ) and be followed by one or more alphanumeric characters.
Yes, like all the other database management systems, DynamoDB also supports all the conditional operators, User can specify a condition that is satisfied for a put, update, or delete operation to work on an item.
Per the documentation, change this:
"ExpressionAttributeValues":{
":p":true
}
To:
"ExpressionAttributeValues":{
":p": {"BOOL": true}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With