How To Update Item In Dynamodb Using Nodejs?
how do i update item in dynamoDB using nodejs ? here is the ITEM list from DynamoDB javascript shell - 'Items': [ { 'EmailId': 'swa@acc.com', 'flag': 1
Solution 1:
You are trying to modify the flag: { 'N': 2 }
which doesnot exist. But you wanted to modify the flag: { 'N': 1 }
value to 2. So try doing like this:
var params = {
TableName: 'users',
Key: {
id: {
'S': req.query.id
},
flag: {
'N': 1
}
},
UpdateExpression: 'SET #flag =:val1',
ExpressionAttributeNames: {
'#flag': 'flag' //COLUMN NAME
},
ExpressionAttributeValues: {
':val1': {
'N': 2
},
}
};
dynamodb.updateItem(params, function(err, data) {
if (err) {
console.log('Error :' + err);
} else {
//subscribe(bodydata.id);
console.log('EndpointArn Saved successful');
console.log('Data :' + JSON.stringify(data.flag));
}
});
Post a Comment for "How To Update Item In Dynamodb Using Nodejs?"