I want to update existing item of dynamoDB table using condition equivalent to like (%) condition of sql
opIdUserId status
- 123-U1 inprogress
- 345-U2 inprogress
- 123-U3 onhold
opIdUserId in my dynamodb is Primary partition key. I want to update status to COMP for opIdUserId field value starting from or contains 123.
this is what I am trying currently but researched and found I can not use KeyConditionExpression for update.
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({region: 'eu-west-1'});
var table = "tablename";
exports.handler = function(event, context, callback){
var params = {
TableName: table,
KeyConditionExpression: "begins_with(opIdUserId, :i)",
UpdateExpression: "set operationStatus = :o",
ExpressionAttributeValues:{
":o":"COMP",
":i":"123-"
},
ReturnValues:"UPDATED_NEW"
};
docClient.update(params, function(err, data) {
if (err) {
callback(err, null);
} else {
callback(null,data);
}
});
}
Please suggest how I can update my item in dynamoDB with specific condition.