[英]how to update item in dynamoDB using nodejs?
how do i update item in dynamoDB using nodejs ? 我如何使用nodejs更新dynamoDB中的项目?
here is the ITEM list from DynamoDB javascript shell - 这是DynamoDB javascript shell的项目列表-
"Items": [
{
"EmailId": "swa@acc.com",
"flag": 1,
"deviceOS": "IOS",
"companyName": "VCC",
"snsEndpoint": "00d0sadas",
"CreatedAt": 22112015,
"Otp": "ABCDEF",
},
i want to update flag value to 2 ... this is my code . 我想将标志值更新为2,这是我的代码。 what do i do??
我该怎么办?? what am i doing wrong ??
我究竟做错了什么 ?? help is appreciated...
感谢帮助...
var params = {
TableName: 'users',
Key: {
id: {
'S': req.query.id
},
flag: {
'N': 2
}
},
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));
}
});
You are trying to modify the flag: { 'N': 2 }
which doesnot exist. 您正在尝试修改不存在的
flag: { 'N': 2 }
。 But you wanted to modify the flag: { 'N': 1 }
value to 2. So try doing like this: 但是您想将
flag: { 'N': 1 }
值修改为2。因此,请尝试执行以下操作:
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));
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.