The goal is to update one of the attributes in the DynamoDB table. Here is the schema:
{
'job_id': {S: jobInfo.job_id} (partition_key),
'company': {S: jobInfo.company},
'title': {S: jobInfo.title},
'posted_on': {S: jobInfo.posted_on},
'clicks': {N: jobInfo.clicks}
}
The primary key of this table is only partition_key and it is job_id. Now I want to increment the clicks value and here is my update param:
let params = {
TableName: 'jobPosts',
Key: {
"job_id": "57a08a5c-ca6c-4056-b892-dc9e6388adb9"
},
UpdateExpression: "add clicks :value",
ExpressionAttributeValues: {
":value": {N: "1"}
},
ReturnValues:"ALL_NEW"
};
ddb.updateItem(params, function(err, data) {
if (err) {
console.log("In DynamoDB error");
console.log(`Error: ${err}`);
} else {
console.log("In DynamoDB Success");
console.log(`Here is the data: ${data}`);
}
});
};
But, I get the ValidationException error with the message The provided key element does not match the schema. Here is the full stack trace:
{
"message": "The provided key element does not match the schema",
"code": "ValidationException",
"time": "2019-11-17T04:23:11.495Z",
"requestId": "4327RBE0UEHSND9Q4M7K44AEEFVV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 37.586092348332265
}
The table doesn't have a composite primary key. It is just partition_key. I don't understand the issue here.